PropertyInfo.SetValue and custom type
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > BizTalk Server > BizTalk Server General > PropertyInfo.SetValue and custom type




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    PropertyInfo.SetValue and custom type  
Vladimir Semenov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-28-05 10: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












[ Post a follow-up to this message ]



    Re: PropertyInfo.SetValue and custom type  
Carlos J. Quintero [VB MVP]


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-28-05 10: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
>
>
>
>
>
>
>







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:46 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register