Sorry, perhaps I wasn't clear enough about what I need. I'm not looking to
convert complex types, just value types (plus Guids and Strings) passed in a
variable of type Object.
I'm using Reflection to retrieve the values, and I want to insert them into
XML attributes. The safest way to do this is with XmlConvert, but it won't
accept an Object type. I can write a big branching statement for all the
possible actual types of my object (per sample code below), but I was hoping
for something a little more elegant.
Dim xmlString as String
Dim value as Object = CType(myStuffFromReflection,
FieldInfo).GetValue(someObj)
If TypeOf(obj) Is String Then
dim s as String = CType(value, String)
xmlString = XmlConvert.ToString(s) ' ToString only has overloads
for strongly-typed variables
ElseIf TypeOf(obj) Is Integer Then
dim i as Integer = CType(value, Integer)
xmlString = XmlConvert.ToString(i)
' etc...
Any suggestions?
Thanks.
Jon
"Jon the Blind" <no****@spamfree.biz> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
I'm looking for a way to retrieve data via
System.Reflection.FieldInfo.GetValue (which returns an Object) and convert
it to XML using XmlConvert.ToString.
XmlConvert accepts only specified data types, so I could have a big ugly
branching Select statement to call the correct ToString overload... but
there must be an easier way.
Any suggestions?
Cheers,
Jon