CSharpFeeds - All your C# feeds in one place.

Monday, August 16, 2010

Hydrating Objects With Expression Trees - Part II

by Paulo Morgado via Paulo Morgado : C# on 8/16/2010 10:19:50 PM

In my previous post I showed how to hydrate objects by creating instances and setting properties in those instances. But, if the intent is to hydrate the objects from data, why not having an expression that does just that? That’s what the member initialization expression is for. To create such an expression we need the constructor expression and the property binding expressions: var properties = objectType.GetProperties(); var bindings = new MemberBinding[properties.Length]; var valuesArray ...

[ read more ]

Hydrating Objects With Expression Trees - Part I

by Paulo Morgado via Paulo Morgado : C# on 8/16/2010 12:55:31 AM

After my post about dumping objects using expression trees, I’ve been asked if the same could be done for hydrating objects. Sure it can, but it might not be that easy. What we are looking for is a way to set properties on objects of an unknown type. For that, we need to generate methods to set each property of the objects. Such methods would look like this expression: Expression<Action<object, object>> expression = (o, v) => ((SomeType)o).Property1 = (PropertyType)v; Unfor ...

[ read more ]

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us