Hi There,
I'm using Reflection to set a property value via PropertyInfo.SetValue(); The property in question is a string, and the object from which I'm getting the value is actually a GUID. I'd like to convert from a GUID to a string in the process - is there any way of defining some kind of implicit cast which will enable this? At the moment I'm getting an error:
"Object of type 'System.Guid' cannot be converted to type 'System.String'."
I guess I could do a type check and manually convert if necessary, but if there's an elegant way of doing it behind the scenes then that would be preferable!
Many thanks.
Edit: I can't really just call the .ToString() method on a GUID as I'd very much like my code to look like this:
propertyInfoInstance.SetValue(classInstance, objectWithValue, null)
where objectWithValue is an int/bool/string/GUID. This works fine for everything except a GUID, as (I think!!) there's an implicit cast available. I could do a type check beforehand and just convert the GUID to a string, but I just get that "There must be a better way..." feeling.