P
Philipp Schumann
Hi,
I have a need for "dynamic type casting": in other words, in a "MyConvert"
method I get passed an Object "value" and a Type "type" and the method
should attempt to convert value into type.
Of course it first tries to obtain the appropriate TypeConverter. However,
for some types there are no applicable type converters.
Consider a custom class "Dummy" from a linked assembly (in my scenario,
neither the Dummy type nor its assembly are "known", meaning any Type from
any assembly could be passed). There is no TypeConverter associated with
Dummy, however, it defines implicit cast operators to convert between Dummy
and String. I would like to know whether there is a standard way of
performing such a "dynamic" or "runtime" cast. I tried Convert.ChangeType()
but that method only works with IConvertible types---and completely ignores
any cast operators defined on any of the two types (that of value, and the
target Type).
Any ideas?
Many thanks,
Phil
I have a need for "dynamic type casting": in other words, in a "MyConvert"
method I get passed an Object "value" and a Type "type" and the method
should attempt to convert value into type.
Of course it first tries to obtain the appropriate TypeConverter. However,
for some types there are no applicable type converters.
Consider a custom class "Dummy" from a linked assembly (in my scenario,
neither the Dummy type nor its assembly are "known", meaning any Type from
any assembly could be passed). There is no TypeConverter associated with
Dummy, however, it defines implicit cast operators to convert between Dummy
and String. I would like to know whether there is a standard way of
performing such a "dynamic" or "runtime" cast. I tried Convert.ChangeType()
but that method only works with IConvertible types---and completely ignores
any cast operators defined on any of the two types (that of value, and the
target Type).
Any ideas?
Many thanks,
Phil