private Func <FieldType> GetMin <FieldType>(SerializedProperty property, MinimumAttribute minimumAttribute, FieldType defaultValue) { if (!string.IsNullOrEmpty(minimumAttribute.Compare)) { var method = fieldInfo.DeclaringType.GetMethod(minimumAttribute.Compare, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var field = fieldInfo.DeclaringType.GetField(minimumAttribute.Compare, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var prop = fieldInfo.DeclaringType.GetProperty(minimumAttribute.Compare, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { if (method.ReturnType != typeof(FieldType)) { Debug.LogWarningFormat(_invalidMethodReturnWarning, property.propertyPath, minimumAttribute.Compare, property.type); } else if (!method.HasSignature(null)) { Debug.LogWarningFormat(_invalidMethodParametersWarning, property.propertyPath, minimumAttribute.Compare); } else { return(() => (FieldType)method.Invoke(method.IsStatic ? null : property.GetOwner <object>(), null)); } } else if (field != null) { if (field.FieldType != typeof(FieldType)) { Debug.LogWarningFormat(_invalidFieldReturnWarning, property.propertyPath, minimumAttribute.Compare, property.type); } else { return(() => (FieldType)field.GetValue(field.IsStatic ? null : property.GetOwner <object>())); } } else if (prop != null) { if (prop.PropertyType != typeof(FieldType) || !prop.CanRead) { Debug.LogWarningFormat(_invalidPropertyReturnWarning, property.propertyPath, minimumAttribute.Compare, property.type); } else { return(() => (FieldType)prop.GetValue(prop.GetGetMethod().IsStatic ? null : property.GetOwner <object>())); } } else { Debug.LogWarningFormat(_missingCompareWarning, property.propertyPath, minimumAttribute.Compare, fieldInfo.DeclaringType.Name); } } return(() => defaultValue); }
private Dictionary <string, MinMax> getBounds(IEnumerable <AccessorMemberInfo> accessorInfoList) { var result = new Dictionary <string, MinMax>(); foreach (var accessorMemberInfo in accessorInfoList) { result.Add(accessorMemberInfo.Name, new MinMax(MinimumAttribute.MinimumFor(accessorMemberInfo), MaximumAttribute.MaximumFor(accessorMemberInfo))); } return(result); }
private MinMax getBounds(MemberInfo memberInfo) { return(new MinMax(MinimumAttribute.MinimumFor(memberInfo), MaximumAttribute.MaximumFor(memberInfo))); }