'Type.GetProperties different properties between Collection and ICollection
I am try to build an expression tree and I have this code
var param = Expression.Parameter(typeof(T), "Foo");
var property = Expression.Property(param, "Bar");
var param2 = Expression.Parameter(property.Type.GetProperty("Item").PropertyType, "x");
Now, Bar is a Collection property of Foo and I declare it as
public Collection<Bar> Bar {get;set;}
I am able to get the Item property once I call the Type.GetProperty

The problem I'm facing now is that the Entity class is autogenerated and it is declared as
public ICollection<Bar> Bar {get;set;}
Once I call the Type.GetProperty on ICollection, the Item property is missing.

Is there a way to get that even when using Interface (e.g. ICollection) since I cannot change the type of the properties of the class. Any help is appreciated.
Solution 1:[1]
Ok I got it now.
var converted = Expression.Convert(property, typeof(Collection<Bar>));
var param2 = Expression.Parameter(converted.Type.GetProperty("Item").PropertyType, "x");
I just need to convert the property type so I can access that property.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lenonskie |
