I am writing an interop between a php service and our crm. One of the things I need to do is make sure that simple types get converted ToString() for use later in a json co
The ToString
method is a virtual one and the default implementation is defined in the Object
class and simply returns the name of the type of the object:
public virtual string ToString()
{
return this.GetType().ToString();
}
int
for example, overrides this method to return a meaningful representation.
What you can do is use reflection to detect whether a type overrides the ToString
method like this:
public static bool OverridesToString(Type type)
{
return type.GetMethod("ToString", new Type[0]).DeclaringType != typeof(object);
}
If it does, there is a very good chance that the ToString
method would return something meaningful.