Invalid match for parameters when displaying a string

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<T> generally works...just found it failing out with string
    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);
        }
    }
+3
source share
1 answer

Chars #, " " .NET/CLR... . , :

char c = text[3];

Dictionary<TKey, TValue> , dictionary[key].

"" , , PropertyInfo.GetIndexParameters() .

+9

All Articles