See below answer.
, .
, , .
implicit explicit :
public class A
{
public static implicit operator string(A a)
{
return "A converted to string";
}
public static explicit operator A(string s)
{
return new A();
}
}
. . , , .
Convert.ChangeType. IConvertible, switch . (. ). , TypeCode, , Enums , IConvertible.GetTypeCode.
:
var d = (decimal)System.Convert.ChangeType("17.4", typeof(decimal));
, :
static TTargetType ParseTo<TTargetType>(string target)
{
return (TTargetType)System.Convert.ChangeType(target, typeof(TTargetType));
}
:
var d = ParseTo<decimal>("17.4");
, :
var d = decimal.Parse("17.4");