private static object ApplyMinConstraints(ConstraintsAttribute constraints, object newValue, IAttribute attribute, PropertyInfo propertyInfo) { switch (constraints.ValueType) { case ConstraintsValueType.IntValue: return(Math.Max(newValue.As <int>(), constraints.IntValue)); case ConstraintsValueType.FloatValue: return(Math.Max(newValue.As <float>(), constraints.FloatValue)); case ConstraintsValueType.Reference: return(Math.Max(newValue.As <float>(), propertyInfo.GetValue(attribute).As <float>())); } throw new InvalidOperationException("invalid value-type for max constraints: " + constraints.ValueType); }
private static object ApplyMinConstraints(ConstraintsAttribute constraints, object newValue, IAttribute attribute, PropertyInfo propertyInfo) { switch (constraints.ValueType) { case ConstraintsValueType.IntValue: return Math.Max(newValue.As<int>(), constraints.IntValue); case ConstraintsValueType.FloatValue: return Math.Max(newValue.As<float>(), constraints.FloatValue); case ConstraintsValueType.Reference: return Math.Max(newValue.As<float>(), propertyInfo.GetValue(attribute).As<float>()); } throw new InvalidOperationException("invalid value-type for max constraints: " + constraints.ValueType); }
private static object ApplyMaxConstraints(ConstraintsAttribute constraints, object newValue, IAttribute attribute, PropertyInfo propertyInfo) { switch (constraints.ValueType) { case ConstraintsValueType.IntValue: return(Math.Min(newValue.As <int>(), constraints.IntValue)); case ConstraintsValueType.FloatValue: return(Math.Min(newValue.As <float>(), constraints.FloatValue)); case ConstraintsValueType.Reference: { var attributeType = attribute.GetType(); var referenceProperty = attributeType.GetProperty(constraints.FieldName.ToCamelCase()); return(Math.Min(newValue.As <float>(), referenceProperty.GetValue(attribute).As <float>())); } } throw new InvalidOperationException("invalid value-type for max constraints: " + constraints.ValueType); }
private static object ApplyMaxConstraints(ConstraintsAttribute constraints, object newValue, IAttribute attribute, PropertyInfo propertyInfo) { switch (constraints.ValueType) { case ConstraintsValueType.IntValue: return Math.Min(newValue.As<int>(), constraints.IntValue); case ConstraintsValueType.FloatValue: return Math.Min(newValue.As<float>(), constraints.FloatValue); case ConstraintsValueType.Reference: { var attributeType = attribute.GetType(); var referenceProperty = attributeType.GetProperty(constraints.FieldName.ToCamelCase()); return Math.Min(newValue.As<float>(), referenceProperty.GetValue(attribute).As<float>()); } } throw new InvalidOperationException("invalid value-type for max constraints: " + constraints.ValueType); }