I have a IReadOnlyList
of instantiated classes. I would like to get all the public
static
fields that exists within each of these classes, and compare their names (the actual variable/field name as strings) to another group of strings (our case from an enumerator value name).
internal static string AttachBindablesToConfig(IReadOnlyList<Drawable> children)
{
for (int i = 0; i < children.Count; i++)
{
var type = children[i].GetType(); // Get the class type
var props = type.GetFields(); // Get fields within class
return (props[0].GetValue(null)).ToString(); // Return a specific, testing purposes
}
return "Failed";
}
// in another class
Children = new Drawable[] { new Class1(), new Class2() };
..AttachBindablesToConfig(Children); // get value and display to screen
public class Class1
{
// find these fields, and return their names (x, y, z) in a string format.
public static someClass x;
public static anotherClass y;
public static int z;
}
This approach does not seem to be working. I would like an explanation as to why it doesn't work, and a clear answer which can hopefully fix this issue.