开发者

Resolve value in C#/.net 2.0

开发者 https://www.devze.com 2023-01-03 11:42 出处:网络
Is there a way to resolve values in a class structure using some xpath-style resolver? Exampel in code:

Is there a way to resolve values in a class structure using some xpath-style resolver?

Exampel in code:

string name = Order.Customer.Firstname;

What i would like to do is something like this:

string name = (string)X.Resol开发者_开发问答ve(Order, "Customer.Firstname");

Is there a way to do this in C#/.net 2.0


You could use Reflection to get out the properties and members of a type. Look at the MSDN page for Type.GetProperty to get started.

That method would give you a PropertyInfo which you can use to query the datatype of the property and to get and set it's value.

0

精彩评论

暂无评论...
验证码 换一张
取 消