//------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnWriteArgumentCheck(MethodWriterBase writer, Operand <TypeTemplate.TArgument> argument, bool isOutput) { if (m_Attribute.MinLength.HasValue) { Static.Void( ApiContract.MinStringLength, argument.CastTo <string>(), writer.Const(m_Attribute.MinLength.Value), writer.Const(m_ParameterInfo.Name), writer.Const(isOutput)); } if (m_Attribute.MaxLength.HasValue) { Static.Void( ApiContract.MaxStringLength, argument.CastTo <string>(), writer.Const(m_Attribute.MaxLength.Value), writer.Const(m_ParameterInfo.Name), writer.Const(isOutput)); } }
//------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnWriteArgumentCheck(MethodWriterBase writer, Operand <TypeTemplate.TArgument> argument, bool isOutput) { Type actualParameterType = TypeTemplate.Resolve <TypeTemplate.TArgument>().UnderlyingType(); if (actualParameterType.IsIntegralType()) { Static.Void( m_CheckMethodTypeLong, argument.CastTo <long>(), writer.Const((long)m_BoundValue), writer.Const(ParameterName), writer.Const(isOutput)); } else if (actualParameterType.IsNumericType()) { Static.Void( m_CheckMethodTypeDouble, argument.CastTo <double>(), writer.Const(m_BoundValue), writer.Const(ParameterName), writer.Const(isOutput)); } else { throw new NotSupportedException(string.Format("InRange is not supported on parameter of type [{0}].", actualParameterType)); } }
//------------------------------------------------------------------------------------------------------------------------------------------------- private void WriteArgumentOrCollectionItemCheck(MethodWriterBase writer, Operand <TypeTemplate.TArgument> argument, bool isOutput) { var actualType = argument.OperandType.UnderlyingType(); Type collectionItemType; if (actualType.IsCollectionType(out collectionItemType) && !(this is ICheckCollectionTypes)) { using (TypeTemplate.CreateScope <TypeTemplate.TItem>(collectionItemType)) { writer.ForeachElementIn(argument.CastTo <IEnumerable <TypeTemplate.TItem> >()).Do((loop, item) => { using (TypeTemplate.CreateScope <TypeTemplate.TArgument>(collectionItemType)) { OnWriteArgumentCheck(writer, item.CastTo <TypeTemplate.TArgument>(), isOutput); } }); } } else { OnWriteArgumentCheck(writer, argument, isOutput); } }
//------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnWriteArgumentCheck(MethodWriterBase writer, Operand <TypeTemplate.TArgument> argument, bool isOutput) { Static.Void(ApiContract.ItemsNotNull, argument.CastTo <System.Collections.IEnumerable>(), writer.Const(ParameterName), writer.Const(isOutput)); }
//------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnWriteArgumentCheck(MethodWriterBase writer, Operand <TypeTemplate.TArgument> argument, bool isOutput) { Static.Void(ApiContract.NotNull, argument.CastTo <object>(), writer.Const(ParameterName), writer.Const(isOutput)); }