|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Exception in Reflection and System.Collections.Generic.Listi have some generic List instances which where created for different class (e.g. List<int> , or List<string>). Now i have a reflection framework in place which tries to get all the objects of the lists. This is what i would do in a "standard" Code for (int i=0; i< List.Count; i++) { object o = List[i] } But i have to use reflection. I have retrieved the "Count" Property via reflection and now i try to get the object via the indexProperty. Type[] typeList = new Type[] { typeof(int) }; PropertyInfo propertyInfo2 = valueType.GetProperty("Item", typeList); now i try for (int i=0; i < count ; i++) { object[] index = new object[1]; index[0] = (int)i; object val2 = propertyInfo.GetValue(value,index); } I always get a ´TargetParameterCountException System.Reflection.TargetParameterCountException was unhandled Message="Parameter count mismatch." Source="mscorlib" StackTrace: at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index) What is wrong with that code? - Dietmar |
|||||||||||||||||||||||