protected override void Validate(object parentInstance, T memberValue, MemberInfo member, ValidationResult result) { if (!GenericNumberUtility.NumberIsInRange(memberValue, this.Attribute.min, this.Attribute.max)) { result.Message = "Number is not in range."; result.ResultType = ValidationResultType.Error; } }
protected override void Validate(object parentInstance, T memberValue, MemberInfo member, ValidationResult result) { if (this.maxValueGetter.Failed) { result.Message = this.maxValueGetter.GetNiceErrorMessage(); result.ResultType = ValidationResultType.Error; return; } this.valueExpressionArgument = memberValue; var max = this.maxValueGetter.GetValue(parentInstance); if (!GenericNumberUtility.NumberIsInRange(memberValue, double.MinValue, max)) { result.Message = "Number is larger than " + max + "."; result.ResultType = ValidationResultType.Error; } }
public static bool CanConvert(this Type from, Type to) { if (from == null) { throw new ArgumentNullException(nameof(from)); } if (to == null) { throw new ArgumentNullException(nameof(to)); } return((from == to) || (to == typeof(object)) || (to == typeof(string)) || from.IsCastableTo(to) || (GenericNumberUtility.IsNumber(from) && GenericNumberUtility.IsNumber(to)) || (ConvertUtility.GetCastDelegate(from, to) != null)); }
protected override void Validate(object parentInstance, T memberValue, MemberInfo member, ValidationResult result) { if (this.minValueGetter.Failed || this.maxValueGetter.Failed) { result.Message = ValueResolverUtility.CombineErrorMessagesWhereFailed(this.minValueGetter, this.maxValueGetter); result.ResultType = ValidationResultType.Error; return; } this.valueExpressionArgument = memberValue; var min = this.minValueGetter.GetValue(parentInstance); var max = this.maxValueGetter.GetValue(parentInstance); if (!GenericNumberUtility.NumberIsInRange(memberValue, min, max)) { result.Message = "Number is not in range."; result.ResultType = ValidationResultType.Error; } }
protected override void DrawPropertyLayout(GUIContent label) { if (this.maxValueGetter.Failed) { SirenixEditorGUI.ErrorMessageBox(this.maxValueGetter.GetNiceErrorMessage()); } this.CallNextDrawer(label); if (this.maxValueGetter.Failed) { return; } T value = this.ValueEntry.SmartValue; var max = this.maxValueGetter.GetValue(); if (!GenericNumberUtility.NumberIsInRange(value, double.MinValue, max)) { this.ValueEntry.SmartValue = GenericNumberUtility.ConvertNumber <T>(max); } }
public override bool CanValidateMember(MemberInfo member, Type memberValueType) { return(GenericNumberUtility.IsNumber(memberValueType)); }
public override bool CanDrawTypeFilter(Type type) { return(GenericNumberUtility.IsNumber(type)); }