I have a generic method that works for most of my custom types. Today I collect unit tests. Type expansion failed string. the string contains two properties of the public instance, Lengthand Chars. When I call GetValue, it throws a "parameter counter mismatch."
I do not need to allow the string. Can I add a restriction on my share sufficient to solve the problem?
Code snippet
public static DataTable ToDataTable<T>(this List<T> items){...
List<string> items = new List<string> { "cookie", "apple", "whatever" };
System.Reflection.PropertyInfo[] props = typeof(string).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
foreach (var item in items)
{
var values = new object[props.Length];
for (var i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
}
source
share