views:

23

answers:

0

Hi,

I need to create a method like this:

object GetPropertyValue(object entity, string databaseColumnName, int index);

that will take any entity, a column name which is represented as a property in entity class and an optional index that is used if DB column is located inside collection property by some index.

For example:

Field entity has a property - Wells, that is a set of Well entities. and I need to get a Well Name of the second well from Wells collection. The point is that I don't know anything about Field entity, I only have an interface - IEntity and I know that it is a field object (not a Field instance, but a business object Field recognised by an end user).

So I call GetPropertyValue(IEntity, "WELL_NAME", 1) to get needed value.

With reflection I'm able to get a Field instance, go through all its properties, relationships properties and find my WellName property, after which I could get a Wells property and call Field.Wells[1].WellName - all via reflection.... The approach sucks :(

Please help me writing down this method better that won't affect performance.

PS: I need use this method, because we have to deal with very old legacy domain model across same legacy UI :(

Thanks, Alex