Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2007

Tip: Looking for answers? Try searching our database.

Casting when using reflection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oldman - 31 Aug 2007 01:50 GMT
I am writing a method that kind of works like the default implmentation of
the serializing logic when using the Serializable attribute.
I have a base "serializer" that is using reflection to determine what
properties to serialize out.  When I am deserializing I know the name of the
property and use reflection to get it.  I know the type of the property from
the PropertyInfo PropertyType.  The problem I have is that I need to take the
serialized value which is a string an convert it to the correct type say a
bool.  How do I do this with the information I have?

Thanks
Ged - 31 Aug 2007 10:00 GMT
Hi Oldman

Have you looked at

Convert.ChangeType(object, Type)

According to MSDN
"Returns an Object with the specified Type and whose value is equivalent to
the specified object."

That should do the trick ;-)

HTH

Ged

>I am writing a method that kind of works like the default implmentation of
> the serializing logic when using the Serializable attribute.
[quoted text clipped - 9 lines]
>
> Thanks
Oldman - 31 Aug 2007 12:06 GMT
Thanks Ged!  I will look into this.  I didn't see that method on the Convert
object.  I aslo found that the IConvertible interface supports a ToType
method.
I will report back if either of these solutions work.

> Hi Oldman
>
[quoted text clipped - 25 lines]
> >
> > Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.