Example #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private StatementScope(StatementBlock statementBlock, bool attachStatementBlock)
        {
            m_Previous = s_Current;
            m_Root     = m_Previous.Root;

            if (m_Previous == null)
            {
                throw new InvalidOperationException("Parent scope is not present.");
            }

            m_StatementBlock = statementBlock;
            m_Writer         = m_Previous.m_Writer;
            m_OwnerMethod    = m_Previous.m_OwnerMethod;
            m_OwnerClass     = m_Previous.m_OwnerClass;
            m_Depth          = m_Previous.Depth + 1;

            m_InheritedLoopStatement      = m_Previous.InheritedLoopStatement;
            m_ThisExceptionBlockType      = ExceptionBlockType.None;
            m_ThisExceptionStatement      = null;
            m_InheritedExceptionStatement = m_Previous.InheritedExceptionStatement;
            m_InheritedExceptionBlockType = m_Previous.InheritedExceptionBlockType;

            m_StatementBlock = (attachStatementBlock ? AttachStatementBlock(statementBlock) : null);
            s_Current        = this;
        }
Example #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(StatementBlock statementBlock, RewriteMode rewriteMode)
        {
            m_Previous = s_Current;
            m_Root     = (m_Previous != null ? m_Previous.Root : this);

            m_StatementBlock = statementBlock;
            m_Writer         = statementBlock.OwnerMethod.TransparentWriter;
            m_OwnerMethod    = statementBlock.OwnerMethod;
            m_OwnerClass     = statementBlock.OwnerMethod.OwnerClass;
            m_Depth          = 1;

            m_ThisExceptionBlockType = ExceptionBlockType.None;
            m_ThisExceptionStatement = null;

            if (m_Previous != null)
            {
                m_InheritedLoopStatement      = m_Previous.InheritedLoopStatement;
                m_InheritedExceptionStatement = m_Previous.InheritedExceptionStatement;
                m_InheritedExceptionBlockType = m_Previous.InheritedExceptionBlockType;
            }

            m_StatementBlock        = statementBlock;
            m_IsRewriteMode         = true;
            m_RewriteInsertionIndex = 0;

            s_Current = this;
        }
Example #3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected void WriteMethodBody(MethodWriterBase methodWriter)
        {
            using (StatementScope.Stash())
            {
                using (new StatementScope(m_OwnerClass, methodWriter, statementBlock: m_Statements))
                {
                    methodWriter.Flush();
                }
            }
        }
Example #4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        internal void AddWriter(MethodWriterBase writer)
        {
            if (writer.IsDecorator)
            {
                writer.SetupDecoratorMode(innerWriters: m_Writers.ToArray());
                m_Writers.Clear();
            }

            m_Writers.Add(writer);
        }
Example #5
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------

        internal HapilForShortSyntax(MethodWriterBase writer, Operand <int> from, Operand <int> to, int increment)
        {
            m_Writer    = writer;
            m_From      = from;
            m_To        = to;
            m_Increment = increment;

            StatementScope.Current.Consume(to);
            StatementScope.Current.Consume(from);
        }
Example #6
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));
                }
            }
Example #7
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            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));
                }
            }
Example #8
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------

        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);
            }
        }
Example #9
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(ClassType ownerClass, MethodWriterBase writer, StatementBlock statementBlock)
        {
            if (s_Current != null)
            {
                throw new InvalidOperationException("Root scope already exists.");
            }

            m_Writer      = writer;
            m_OwnerMethod = (writer != null ? writer.OwnerMethod : null);
            m_OwnerClass  = ownerClass;
            m_Depth       = 0;

            m_InheritedLoopStatement      = null;
            m_ThisExceptionBlockType      = ExceptionBlockType.None;
            m_ThisExceptionStatement      = null;
            m_InheritedExceptionStatement = null;
            m_InheritedExceptionBlockType = ExceptionBlockType.None;

            m_Previous = null;
            m_Root     = this;
            s_Current  = this;

            m_StatementBlock = AttachStatementBlock(statementBlock);
        }
Example #10
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));
            }
Example #11
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------

        protected abstract void OnWriteArgumentCheck(MethodWriterBase writer, Operand <TypeTemplate.TArgument> argument, bool isOutput);
 //-----------------------------------------------------------------------------------------------------------------------------------------------------
 public EfEntityConfigurationWriter(ITypeMetadata metadata, MethodWriterBase method, Operand<DbModelBuilder> model)
 {
     _model = model;
     _method = method;
     _metadata = metadata;
 }
Example #13
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));
            }
        //-----------------------------------------------------------------------------------------------------------------------------------------------------
        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;
        }