Again: Reflection and array´s...
-
Hello everybody! My problem is to get/set individual array items which are instanced via reflection. To give you an overwiew here´s some code: *************************************************** System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.LoadFrom(dllfilename); foreach(Type assemblyType in assembly.GetTypes()) { if (assemblyType.IsClass) objInstance = Activator.CreateInstance(viptype); foreach(FieldInfo f in objInstance.GetFields(BindingFlags.Public | BindingFlags.Instance)) { if (f.FieldType.IsArray) { // read every array value! // f.GetValue(objInstance) returns only a complete value (and I don´t know how to handle this) // How can I access to every array item itself??? } else { // do something different. This is working fine! } } } ************************************************* And the source from the assembly looks something like that (extremely shortened, but same structure): ************************ public class myClass { public int ID; // Test public int Test; // Array public int array[15]; } ************************ How can I get in the source at the top for example the 10th integer of the array? Please help me Norman-Timo
-
Hello everybody! My problem is to get/set individual array items which are instanced via reflection. To give you an overwiew here´s some code: *************************************************** System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.LoadFrom(dllfilename); foreach(Type assemblyType in assembly.GetTypes()) { if (assemblyType.IsClass) objInstance = Activator.CreateInstance(viptype); foreach(FieldInfo f in objInstance.GetFields(BindingFlags.Public | BindingFlags.Instance)) { if (f.FieldType.IsArray) { // read every array value! // f.GetValue(objInstance) returns only a complete value (and I don´t know how to handle this) // How can I access to every array item itself??? } else { // do something different. This is working fine! } } } ************************************************* And the source from the assembly looks something like that (extremely shortened, but same structure): ************************ public class myClass { public int ID; // Test public int Test; // Array public int array[15]; } ************************ How can I get in the source at the top for example the 10th integer of the array? Please help me Norman-Timo
Norman-Timo wrote: How can I get in the source at the top for example the 10th integer of the array? It is reflecting against what was just loaded into memory, there will be no value in the 10th position of the array. - Nick Parker
My Blog | My Articles -
Hello everybody! My problem is to get/set individual array items which are instanced via reflection. To give you an overwiew here´s some code: *************************************************** System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.LoadFrom(dllfilename); foreach(Type assemblyType in assembly.GetTypes()) { if (assemblyType.IsClass) objInstance = Activator.CreateInstance(viptype); foreach(FieldInfo f in objInstance.GetFields(BindingFlags.Public | BindingFlags.Instance)) { if (f.FieldType.IsArray) { // read every array value! // f.GetValue(objInstance) returns only a complete value (and I don´t know how to handle this) // How can I access to every array item itself??? } else { // do something different. This is working fine! } } } ************************************************* And the source from the assembly looks something like that (extremely shortened, but same structure): ************************ public class myClass { public int ID; // Test public int Test; // Array public int array[15]; } ************************ How can I get in the source at the top for example the 10th integer of the array? Please help me Norman-Timo
Use the methods as given in the Array base class, or access it via the "Item" property. top secret xacc-ide 0.0.1