|
Home > Archive > BizTalk Server General > October 2005 > PropertyInfo.SetValue and custom type
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
PropertyInfo.SetValue and custom type
|
|
| Vladimir Semenov 2005-10-28, 5:03 pm |
| Hi all,
I have a problem with PropertyInfo.SetValue().
Task:
There is a generic code updating object properties using reflection. I don't
want to change this code.
One of property is of a custom type which is fully controlled by me.
Problem:
When the generic code tries to pass integer type to SetValue an exception is
thrown.
Question:
What should I do with custom type to ensure that SetValue automatically
converts integer to my custom type?
1) Declare constructor,
2) Declare TypeConverter
3) Implement conversion operator
4) ????
Thanks advance,
Vladimir
| |
| Carlos J. Quintero [VB MVP] 2005-10-28, 5:03 pm |
| The implementation of the SetValue method of the ReflectPropertyDescriptor
class, derived from the abstract PropertyDescriptor, retrieves the "Set"
method of the object class that takes your type as parameter and calls it
using the Invoke method passing the value. AFAIK, converters are not
involved here (they are related to UI components) so try with a conversion
operator. If that fails, the calling code should be modified to use the
IConvertible interface that you should implement in your type.
--
Best regards,
Carlos J. Quintero
MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"Vladimir Semenov" <wsemenov@hotmail.com> escribió en el mensaje
news:uYyvlow2FHA.2472@TK2MSFTNGP12.phx.gbl...
> Hi all,
>
> I have a problem with PropertyInfo.SetValue().
>
> Task:
> There is a generic code updating object properties using reflection. I
> don't
> want to change this code.
> One of property is of a custom type which is fully controlled by me.
>
> Problem:
> When the generic code tries to pass integer type to SetValue an exception
> is
> thrown.
>
> Question:
> What should I do with custom type to ensure that SetValue automatically
> converts integer to my custom type?
> 1) Declare constructor,
> 2) Declare TypeConverter
> 3) Implement conversion operator
> 4) ????
>
> Thanks advance,
>
> Vladimir
>
>
>
>
>
>
>
|
|
|
|
|