示例#1
0
        public static MemberInfo[] GetMembers(Type targetType, OSCReflectionType memberTypes)
        {
            var members     = new List <MemberInfo>();
            var typeMembers = targetType.GetMembers(_bindingFlags);

            foreach (var memberInfo in typeMembers)
            {
                if (memberInfo.GetCustomAttributes(typeof(ObsoleteAttribute), true).Count() > 0)
                {
                    continue;
                }

                if ((memberTypes & OSCReflectionType.Field) == OSCReflectionType.Field && memberInfo is FieldInfo)
                {
                    members.Add(memberInfo);
                }
                else if ((memberTypes & OSCReflectionType.Property) == OSCReflectionType.Property && memberInfo is PropertyInfo)
                {
                    members.Add(memberInfo);
                }
                else if ((memberTypes & OSCReflectionType.Method) == OSCReflectionType.Method && memberInfo is MethodInfo)
                {
                    var methodInfo = (MethodInfo)memberInfo;
                    if (methodInfo.IsSpecialName)
                    {
                        continue;
                    }

                    members.Add(memberInfo);
                }
            }

            return(members.ToArray());
        }
        private OSCReflectionProperty(object target, FieldInfo fieldInfo)
        {
            _target       = target;
            _propertyType = OSCReflectionType.Field;
            _propertyName = fieldInfo.Name;

            _fieldInfo = fieldInfo;

            _valueType = fieldInfo.FieldType;
        }
示例#3
0
        private OSCReflectionProperty(object target, MethodInfo methodInfo)
        {
            _target       = target;
            _propertyType = OSCReflectionType.Method;
            _propertyName = methodInfo.Name;

            _methodInfo      = methodInfo;
            _methodWriteType = OSCReflection.GetMethodWriteType(methodInfo);
            _methodReadType  = OSCReflection.GetMethodReadType(methodInfo);
        }
        private OSCReflectionProperty(object target, PropertyInfo propertyInfo)
        {
            _target       = target;
            _propertyType = OSCReflectionType.Property;
            _propertyName = propertyInfo.Name;

            _propertyInfo   = propertyInfo;
            _propertyGetter = propertyInfo.GetGetMethod();
            _propertySetter = propertyInfo.GetSetMethod();

            _valueType = propertyInfo.PropertyType;
        }
        public OSCReflectionMemberDrawer(
            SerializedProperty serializedProperty,
            Type memberType,
            OSCReflectionAccess reflectionAccess,
            OSCReflectionType reflectionType)
        {
            // Setup.
            _serializedProperty = serializedProperty;
            _memberType         = memberType;
            _reflectionAccess   = reflectionAccess;
            _reflectionType     = reflectionType;

            // Setup contents.
            _memberContent = _memberDefaultContent;
            _targetContent = _targetDefaultContent;

            // Find internal properties.
            _targetProperty = _serializedProperty.FindPropertyRelative("Target");
            _memberProperty = _serializedProperty.FindPropertyRelative("MemberName");
        }
示例#6
0
        public static MemberInfo[] GetMembersByType(Type targetType, Type valueType, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
        {
            var members       = new List <MemberInfo>();
            var targetMembers = GetMembers(targetType, memberTypes);

            foreach (var memberInfo in targetMembers)
            {
                if (memberInfo is FieldInfo)
                {
                    var fieldInfo = (FieldInfo)memberInfo;

                    if (fieldInfo.FieldType == valueType)
                    {
                        members.Add(memberInfo);
                    }
                }
                else if (memberInfo is PropertyInfo)
                {
                    var propertyInfo = (PropertyInfo)memberInfo;

                    if (!CheckAccess(propertyInfo, valueAccess))
                    {
                        continue;
                    }

                    if (propertyInfo.PropertyType == valueType)
                    {
                        members.Add(memberInfo);
                    }
                }
                else if (memberInfo is MethodInfo)
                {
                    var methodInfo = memberInfo as MethodInfo;

                    if (!CheckAccess(methodInfo, valueAccess))
                    {
                        continue;
                    }

                    if (valueAccess == OSCReflectionAccess.Any)
                    {
                        if (GetMethodReadType(methodInfo) == valueType ||
                            GetMethodWriteType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                    if (valueAccess == OSCReflectionAccess.ReadWrite)
                    {
                        if (GetMethodReadType(methodInfo) == valueType ||
                            GetMethodWriteType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                    if (valueAccess == OSCReflectionAccess.Read)
                    {
                        if (GetMethodReadType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                    if (valueAccess == OSCReflectionAccess.Write)
                    {
                        if (GetMethodWriteType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                }
            }

            return(members.ToArray());
        }
示例#7
0
 public static MemberInfo[] GetMembersByType(object memberTarget, Type valueType, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
 {
     return(GetMembersByType(memberTarget.GetType(), valueType, valueAccess, memberTypes));
 }
示例#8
0
 public static MemberInfo[] GetMembers(object memberTarget, OSCReflectionType memberTypes)
 {
     return(GetMembers(memberTarget.GetType(), memberTypes));
 }
示例#9
0
        public static MemberInfo[] GetMembersByAccess(Type targetType, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
        {
            var members       = new List <MemberInfo>();
            var targetMembers = GetMembers(targetType, memberTypes);

            foreach (var memberInfo in targetMembers)
            {
                if (memberInfo is FieldInfo)
                {
                    members.Add(memberInfo);
                }
                else if (memberInfo is PropertyInfo)
                {
                    var propertyInfo = (PropertyInfo)memberInfo;

                    if (!CheckAccess(propertyInfo, valueAccess))
                    {
                        continue;
                    }

                    members.Add(memberInfo);
                }
                else if (memberInfo is MethodInfo)
                {
                    var methodInfo = memberInfo as MethodInfo;

                    if (!CheckAccess(methodInfo, valueAccess))
                    {
                        continue;
                    }

                    members.Add(memberInfo);
                }
            }

            return(members.ToArray());
        }
示例#10
0
 public static MemberInfo[] GetMembersByAccess(object target, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
 {
     return(GetMembersByAccess(target.GetType(), valueAccess, memberTypes));
 }