コード例 #1
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            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));
                }
            }
コード例 #2
0
ファイル: InRangeAttribute.cs プロジェクト: bitfringe/Hapil
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            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));
                }
            }
コード例 #3
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            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));
            }
コード例 #4
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            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));
            }
コード例 #5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------
        private bool TryGetPropertyDefaultValue(MethodWriterBase writer, PropertyInfo property, out IOperand<TT.TProperty> valueOperand)
        {
            var attribute = property.GetCustomAttribute<DefaultValueAttribute>(inherit: true);

            if ( attribute != null && attribute.Value != null )
            {
                if ( property.PropertyType.IsInstanceOfType(attribute.Value) )
                {
                    if ( attribute.Value is System.Type )
                    {
                        valueOperand = Static.Func<string, bool, Type>(
                            Type.GetType,
                            writer.Const(((Type)attribute.Value).AssemblyQualifiedName),
                            writer.Const(true)).CastTo<TT.TProperty>();
                    }
                    else
                    {
                        var valueOperandType = typeof(Constant<>).MakeGenericType(attribute.Value.GetType());
                        valueOperand = ((IOperand)Activator.CreateInstance(valueOperandType, attribute.Value)).CastTo<TT.TProperty>();
                    }
                }
                else if ( attribute.Value is string )
                {
                    valueOperand = Static.Func(ParseUtility.Parse<TT.TProperty>, writer.Const((string)attribute.Value));
                }
                else
                {
                    throw new ContractConventionException(
                        this.GetType(), Context.TypeKey.PrimaryInterface, property, "Specified default value could not be parsed");
                }

                return true;
            }

            valueOperand = null;
            return false;
        }