System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetEntryAssembly();
Type[] Types = myAssembly.GetTypes();
foreach (Type myType in Types)
{
if (myType.BaseType == null) continue;
if (myType.BaseType == typeof(Form))
{
IEnumerable<Component> x = EnumerateComponents(myType)
}
}
Why under myType
I get exceptions and how to solve them?
UPDATE
method which should process myType
public IEnumerable<Component> EnumerateComponents(object formobj)
{
var l = (from field in formobj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
where typeof(Component).IsAssignableFrom(field.FieldType)
let component = (Component)field.GetValue(formobj)
where component != null
select component);
return l;
}
Aucun commentaire:
Enregistrer un commentaire