public void Check(object obj, FieldInfo field, Attribute attribute, object context) { var val = field.GetValue(obj); if (!(val is IConvertible)) { throw new InvalidOperationException(SanityChecker.CreateExceptionMessage(field, obj, "is required to be non-negative but its type cannot be compared to numbers.", context)); } if (Convert.ToDouble(val) < 0.0) { throw new InvalidValueException(SanityChecker.CreateExceptionMessage(field, obj, "must not be negative.", context)); } }
public void Check(object obj, FieldInfo field, Attribute attribute, object context) { var val = field.GetValue(obj); if (val != null && val.GetType().IsSubclassOf(typeof(UnityEngine.Object))) // Handle Unity's pseudo null values { if ((UnityEngine.Object)val == null) { throw new MissingReferenceException(SanityChecker.CreateExceptionMessage(field, obj, "is missing a reference. Please assign it in the editor.", context)); } } if (val == null) { throw new MissingReferenceException(SanityChecker.CreateExceptionMessage(field, obj, "is missing a reference. Please assign it in the editor.", context)); } }
public void Check(object obj, FieldInfo field, Attribute attribute, object context) { var val = field.GetValue(obj); if (!(val is IConvertible)) { throw new InvalidOperationException(SanityChecker.CreateExceptionMessage(field, obj, "is required to be greater than a given value but its type cannot be compared to numbers.", context)); } double comparedValue = ((GreaterThanAttribute)attribute).Value; if (!(Convert.ToDouble(val) > comparedValue)) { throw new InvalidValueException(SanityChecker.CreateExceptionMessage(field, obj, "must be greater than " + comparedValue + ".", context)); } }
public void Check(object obj, FieldInfo field, Attribute attribute, object context) { var val = field.GetValue(obj); if (val == null) { throw new InvalidValueException(SanityChecker.CreateExceptionMessage(field, obj, "must not be null. Please assign a value to the string.", context)); } if (!(val is string)) { throw new InvalidOperationException(SanityChecker.CreateExceptionMessage(field, obj, "is not a string.", context)); } if (string.IsNullOrEmpty(val.ToString())) { throw new InvalidValueException(SanityChecker.CreateExceptionMessage(field, obj, "must not be empty. Please assign a value to the string.", context)); } }