I got this code thats works :
var assembly= Assembly.LoadFrom("D:\\...\\mydll.dll");
Type rmType = assembly.GetType(specific_class_with_namespace);
bject MyObjj = Activator.CreateInstance(rmType);
PropertyInfo[] pi = rmType.GetProperties();
foreach(PropertyInfo prop in pi)
{
Console.WriteLine("Prop: {0}", prop.Name);
}
The thing is that the property I wanna access to is a IEnumerable<IWidget>, where IWidget is an internal class of my dll. So in my current code I can’t test the Type of my PropertyInfo (and cast it right ? :/)
The final objective is to access to the Name property of my IWidget. Something like :
foreach(var widget in myProperty)
{
string widgetName = widget.Name;
}
I read a couple of tutorials on the web and some questions here on SO, but none helped me for my IEnumerable<customType> problem :/
EDIT :
when I do :
PropertyInfo ItemsProperty = rmType.GetProperty("Items");
var ItemsPropertyValue = ItemsProperty.GetValue(rmType, null);
I can a XamlParseException with the “most” InnerException being “Object does not match target type”…
You can test you property for being of type
IEnumerableand then inforeachloop withreflectionyou can access property of item with nameName.To test for being IEnumerable you can use
typeof(IEnumerable).IsAssignableFrom(prop.PropertyType)ortype.GetGenericTypeDefinition() == typeof(IEnumerable<>).EDIT:
In
GetValueyou should put instance not the type: