private void WriteIntegerRange(ILWriter writer, PropertyInfo property, IntegerRangeAttribute integerRangeAttribute) { var validationKind = ValidationKind.IntegerRange; var signedSet = new HashSet <Type>() { typeof(sbyte), typeof(short), typeof(int), typeof(long) }; var unsignedSet = new HashSet <Type>() { typeof(byte), typeof(ushort), typeof(uint), typeof(ulong) }; LocalBuilder local; if (signedSet.Contains(property.PropertyType)) { local = writer.DeclareLocal <long>(); } else if (unsignedSet.Contains(property.PropertyType)) { local = writer.DeclareLocal <ulong>(); } else { WriteNotApplicableResult(writer, validationKind); writer.Return(); return; } writer.LoadFirstParameter(); writer.GetPropertyValue(property); writer.Cast(property.PropertyType, local.LocalType); writer.SetLocal(local); if (integerRangeAttribute.HasMinimum && integerRangeAttribute.HasMaximum) { if (integerRangeAttribute.Minimum > integerRangeAttribute.Maximum) { var message = CommonErrors.IntegerRangeValidationHasMinGreaterThanMax.WithValues(property.ReflectedType.Name, property.Name); throw new IncorrectValidationAttributeException(typeof(IntegerRangeAttribute), message); } } if (integerRangeAttribute.HasMinimum) { writer.LoadLocal(local); writer.LoadInt64(integerRangeAttribute.Minimum); var isGreaterThanOrEqual = writer.IfLessThan(); WriteFailureResult(writer, validationKind, CommonResults.IntegerPropertyIsTooLow.WithValues(property.ReflectedType.Name, property.Name, integerRangeAttribute.Minimum)); writer.Return(); writer.MarkLabel(isGreaterThanOrEqual); } if (integerRangeAttribute.HasMaximum) { writer.LoadLocal(local); writer.LoadInt64(integerRangeAttribute.Maximum); var isLessThanOrEqual = writer.IfGreaterThan(); WriteFailureResult(writer, validationKind, CommonResults.IntegerPropertyIsTooHigh.WithValues(property.ReflectedType.Name, property.Name, integerRangeAttribute.Maximum)); writer.Return(); writer.MarkLabel(isLessThanOrEqual); } }