Here is the code I have :
public class Test
{
string a;
int b;
}
public class Test2
{
string c;
string d
int e;
}
I’m compiling it to a DLL and extracting both Classes with :
var library = Assembly.LoadFrom(libraryPath);
IEnumerable<Type> types = library.GetTypes();
and then “foreach type in types”, I’d like to get a list of my variables but don’t know how to do it… I’m trying :
var lib = Activator.CreateInstance(type);
Type myType = lib.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
foreach (PropertyInfo prop in props)
{
// Do something with propValue
}
“props” is empty all the time…
Any help ?
What you show are NOT properties but are Fields – so you need to call
myType.GetFields(). For private fields etc. you will need to call with the appropriateBindingFlags.