Accessing object property as string and setting its value
Posted
by ludicco
on Stack Overflow
See other posts from Stack Overflow
or by ludicco
Published on 2010-05-25T13:44:36Z
Indexed on
2010/05/25
13:51 UTC
Read the original article
Hit count: 316
Hello there, I have an object in csharp from the class Account each account have a owner, reference, etc.
One way I can access an accounts properties is through accessors like
account.Reference;
but I would like to be able to access it using dynamic string selectors like:
account["PropertyName"];
just like in javascript. so I would have account["Reference"] which would return the value...but I also would like to be able to sign a new value after that like:
account["Reference"] = "124ds4EE2s";
I've noticed I can use
DataBinder.Eval(account,"Reference")
to get a property based on a string, but using this I can't sign a value to the property.
Any idea on how I could do that?
Thanks a lot
© Stack Overflow or respective owner