I am trying to serialize an object and want to know if a certain type can be used by XmlReader.ReadElementContentAsObject()
or by ReadElementContentAs()
.
Can I ask a type if it is a CLR type so I know that I can pass it to these methods?
if(myType.IsCLRType) // how can I find this property?
myValue = _cReader.ReadElementContentAsObject();
I think I'm looking for this list: http://msdn.microsoft.com/en-us/library/xa669bew.aspx
You can probably get most of the way there with Type.GetTypeCode(type)
, but frankly I expect your best bet is more simple:
static readonly HashSet<Type> supportedTypes = new HashSet<Type>(
new[] { typeof(bool), typeof(string), typeof(Uri), typeof(byte[]), ... });
and check with supportedTypes.Contains(yourType)
.
There is no magic pre-defined list that will match exactly the "this list" you have in mind. For example, TypeCode
doesn't note byte[]
or Uri
.