日期:2014-05-17  浏览次数:20863 次

为什么GetProperty()获取不了属性
我不太懂反射原理,只知道这几个方法。
平常使用的时候,GetProperty()都能获取值。
但是linq得到的对象IEnumerable<T>就取不到了

如果IEnumerable<T>.GetProperties()就可以把所有值都取出来
但是IEnumerable<T>.GetProperty(name)就永远是null

怎么办呀


        public static string ContactText<T>(this IEnumerable<T> en, string name, string separator)
        {
            string result = string.Empty;

            if (en is Array)
            {
                result = ContactEnumerable(en, null, separator);
            }
            else
            {
                result = ContactEnumerable(en, name, separator);
            }
            if (result.Contains(separator))
                result = result.Substring(separator.Length);
            return result;
        }

        public static string ContactEnumerable<T>(IEnumerable<T> en, string name, string separator)
        {
            System.Reflection.PropertyInfo pi = null;
            StringBuilder sb = new StringBuilder();

            if (name == null)
            {
                foreach (object o in en)
                    sb.Append(string.Concat(separator, o));
            }