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
Post a Comment