have a look at this code please:
public void BindElements<T>(IEnumerable<T> dataObjects)
{
Paragraph para = new Paragraph();
foreach (T item in dataObjects)
{
InlineUIContainer uiContainer =
this.CreateElementContainer(item.FirstName ????? )
para.Inlines.Add(uiContainer);
}
FlowDocument flowDoc = new FlowDocument(para);
this.Document = flowDoc;
}
When in write in Visual Studio “item.XXX” I should get the properties from my entitiy like .FirstName or .LastName. I do not know wether dataObjects is an IEnumerable or IOrder etc… it must be generic!
How can I get the real properties form item ? Only with Reflection?
Oded is right, it doesn’t seem (to him or me) to make any sense to try and make this method generic. You are trying to genericize a method whose functionality is actually specific to a few types.
Now, that said, it seems the bulk of the function is independent of this property you want to access. So why not split it into two parts: that which can be genericized, and that which can’t:
Something like this:
Then your overloads dealing with specific types, e.g.,
IPerson, can reuse this code (which I suspect may be what you were after all along—code reuse):…then for
IOrder:…and so on.