clojure.lang.Reflector.GetProperty C# (CSharp) Метод

GetProperty() публичный статический Метод

public static GetProperty ( Type t, String name, bool getStatics ) : PropertyInfo
t System.Type
name String
getStatics bool
Результат System.Reflection.PropertyInfo
        public static PropertyInfo GetProperty(Type t, String name, bool getStatics)
        {
            BindingFlags flags = BindingFlags.Public;
            if (getStatics)
                flags |= BindingFlags.Static | BindingFlags.FlattenHierarchy;
            else
                flags |= BindingFlags.Instance;

            List<Type> typesToCheck = new List<Type>();
            typesToCheck.Add(t);

            if (t.IsInterface && !getStatics)
                typesToCheck.AddRange(t.GetInterfaces());

            List<PropertyInfo> pinfos = new List<PropertyInfo>();

            foreach (Type type in typesToCheck)
            {
                IEnumerable<PropertyInfo> einfo
                     = type.GetProperties(flags).Where(info => info.Name == name && info.GetIndexParameters().Length == 0);
                pinfos.AddRange(einfo);
            }

            if (pinfos.Count == 0)
                return null;

            if (pinfos.Count == 1)
                return pinfos[0];

            // Look for the one declared on this type, if it exists
            // This handles the situation where we have overloads.
            foreach (PropertyInfo pinfo in pinfos)
                if (pinfo.DeclaringType == t)
                    return pinfo;

            return null;
        }