Ejemplo n.º 1
0
        internal static MemberInfo[] GetInstanceFieldsAndProperties(Type type, bool publicOnly)
        {
#if WINRT
            System.Collections.Generic.List<MemberInfo> members = new System.Collections.Generic.List<MemberInfo>();
            foreach(FieldInfo field in type.GetRuntimeFields())
            {
                if(field.IsStatic) continue;
                if(field.IsPublic || !publicOnly) members.Add(field);
            }
            foreach(PropertyInfo prop in type.GetRuntimeProperties())
            {
                MethodInfo getter = Helpers.GetGetMethod(prop, true, true);
                if(getter == null || getter.IsStatic) continue;
                if(getter.IsPublic || !publicOnly) members.Add(prop);
            }
            return members.ToArray();
#else
            BindingFlags flags = publicOnly ? BindingFlags.Public | BindingFlags.Instance : BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
            PropertyInfo[] props = type.GetProperties(flags);
            FieldInfo[] fields = type.GetFields(flags);
            MemberInfo[] members = new MemberInfo[fields.Length + props.Length];
            props.CopyTo(members, 0);
            fields.CopyTo(members, props.Length);
            return members;
#endif
        }
Ejemplo n.º 2
0
        internal static MemberInfo GetInstanceMember(TypeInfo declaringType, string name)

        {
            PropertyInfo prop = declaringType.GetDeclaredProperty(name);

            MethodInfo method;

            if (prop != null && (method = Helpers.GetGetMethod(prop, true, true)) != null && !method.IsStatic)
            {
                return(prop);
            }



            FieldInfo field = declaringType.GetDeclaredField(name);

            if (field != null && !field.IsStatic)
            {
                return(field);
            }



            return(null);
        }