Components
Reference

Type conversion

The Smart Conversion library allows you to convert any datatype to another data type, without risking type conversion exceptions.

Heuristics are used to convert values from one type to another.

Examples:

string s1 = "25";
string s2 = "0";
string s3 = "";
string s4 = null;
string s5 = "a";

int a = s1.To<int>(); // returns 25
int b = s2.To<int>(); // returns 0
int c = s3.To<int>(); // returns 0
int d = s4.To<int>(); // returns 0
int e = s5.To<int>(); // returns 0
int? e = s1.To<int?>(); // returns 25
int? f = s2.To<int?>(); // returns 0
int? g = s3.To<int?>(); // returns null
int? h = s4.To<int?>(); // returns null
int? i = s5.To<int?>(); // returns null

As you can see, when a conversion makes sense, the value is converted. If not, it returns the default value of the target type (for a nullable value type, the default value is null)