( ) , ( , ). deserialize, , , , .
, , , , , . - , , E - XmlNode, , newVar - T, . - T ( /cast ) , / - ( ):
MethodInfo convertMethod;
if( Type.GetTypeCode(type) != TypeCode.String )
convertMethod = typeof(XmlConvert).GetMethod ( "To" + type.Name );
else
convertMethod = E.InnerText.GetType().GetMethod("Clone");
if( convertMethod == null )
{
}
else
{
if( Type.GetTypeCode (type)!= TypeCode.String )
newVar = (T)convertMethod.Invoke( null, new object[] { E.InnerText } );
else
newVar = (T)convertMethod.Invoke ( E.InnerText, new object[]{} );
}
( , ToString() - ).
( ) - ( , , ):
MethodInfo convertMethod;
if( Type.GetTypeCode(type) != TypeCode.String )
convertMethod = typeof(XmlConvert).GetMethod ( "ToString", new Type[] {typeof(T)} );
else
convertMethod = typeof(string).GetMethod("Clone");
if( convertMethod == null )
{
}
else
{
string str;
if( Type.GetTypeCode (type)!= TypeCode.String )
str = (string)convertMethod.Invoke( null, new object[] { Value } );
else
str = (string)convertMethod.Invoke ( Value, new object[]{} );
}
T , Value T, . , ToString, T. .