CallByName equivalent

Posts   
 
    
Posts: 34
Joined: 03-Oct-2005
# Posted on: 02-Dec-2005 10:57:22   

This may just be me being dense, or my lack of .NET knowledge, but is their an equivalent of the VB6 CallByName function...?

What I want to be able to do is set a property of an entity, but inside a generic class where the name of the property to call is passed in as string.

I am already using the Microsoft.VisualBasic.CallByName function and it works OK, but it seems that there ought to be a more ".NET pure" way of doing it...

Cheers

Matt

Posts: 34
Joined: 03-Oct-2005
# Posted on: 02-Dec-2005 11:05:32   

It looks like I can do what I need using "SetNewFieldValue" and "GetCurrentFieldValue" on the Entity is question, but I would still like to know if there is a general .NET method

On a related note - is there any reason why "SetNewFieldValue" has an override that takes the field name as a string, but "GetCurrentFieldValue" does not (it only accepts the index...) ?

Thanks

Matt

Posts: 34
Joined: 03-Oct-2005
# Posted on: 02-Dec-2005 11:14:52   

Except that "SetNew..." and "GetCurrent..." work directly with the fields, and I want to be able to set related entites using a generic method..

Any thoughts gratefully recieved...!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 02-Dec-2005 11:29:00   

Use reflection. Get a propertyinfo object and set the instance directly through that propertyinfo (or propertydescriptor, same effect).

Frans Bouma | Lead developer LLBLGen Pro
Posts: 34
Joined: 03-Oct-2005
# Posted on: 02-Dec-2005 12:12:07   

Bingo...

I new Relflection had to be the way, but couldn't quite get my head around it.

Thanks Franz

Matt