Replacement for "TypeDescriptor" class (since it's not implemented on Windows Phone 7)? -


i have simple function wrote million years tries convert string type. works great values types, numbers, enums, datetimes etc use time when parsing xml file values, web request results - whatever.

however code won't work on windows phone 7 because "typedescriptor" object not implemented (see pc code sample below). recommendations on how can implement simple string -> type converter on phone?

here's existing code (written non-phones):

    internal t changetype<t>(object o)     {         type typeoft = typeof(t);          // null         if (o == null)         {             return default(t);         }          // types same         if (typeoft == o.gettype())         {             return (t)o;         }          // these different type - try see         // if there's built in convertor         // note: "typedescriptor" not implemented on windows phone 7         typeconverter convertor = typedescriptor.getconverter(typeoft);          if (convertor.canconvertfrom(o.gettype()))         {             return (t)convertor.convertfrom(o);         }         else         {             throw new exception("can not convert value type: " + typeoft.name);         }      } 

there's msdn article on how to: implement type converter.

yes, reinventing wheel compared exists in full framework. unfortunately problem ahve deal in compact framework though.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -