示例#1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region IMutableOperand Members

        IOperand IMutableOperand.Assign(IOperand value)
        {
            if (value is IOperand <T> )
            {
                return(Assign((IOperand <T>)value));
            }
            else
            {
                return(Assign(value.CastTo <T>()));
            }
        }
示例#2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region IHapilUsingSyntax Members

        public void Do(Action body)
        {
            using (var scope = new StatementScope(m_BodyBlock))
            {
                var writer     = scope.Writer;
                var disposable = writer.Local <IDisposable>(initialValue: m_Disposable.CastTo <IDisposable>());

                writer.Try(() => {
                    body();
                })
                .Finally(() => {
                    writer.If(disposable != writer.Const <IDisposable>(null)).Then(() => {
                        disposable.Void(x => x.Dispose);
                    });
                });
            }
        }
示例#3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region IHapilForeachDoSyntax<TItem> Members

        public void Do(Action <ILoopBody, Local <TElement> > body)
        {
            using (var scope = new StatementScope(m_BodyBlock, loopStatement: this))
            {
                var writer     = scope.Writer;
                var enumerator = writer.Local <IEnumerator <TElement> >();

                enumerator.Assign(m_Collection.CastTo <IEnumerable <TElement> >().Func <IEnumerator <TElement> >(x => x.GetEnumerator));

                writer.Using(enumerator).Do(() => {
                    m_InnerWhile = (WhileStatement)writer.While(enumerator.Func <bool>(e => e.MoveNext));
                    m_InnerWhile.Do(loop => {
                        m_Element.Assign(enumerator.Prop(e => e.Current));
                        body(this, m_Element);
                    });
                });
            }
        }
示例#4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public void VisitOperand <T>(ref IOperand <T> operand)
        {
            if (operand != null)
            {
                IOperand replaceable = operand;

                if (OnFilterOperand(operand))
                {
                    OnVisitOperand(ref replaceable);
                }

                if (ReferenceEquals(operand, replaceable))
                {
                    VisitAcceptor(operand as IAcceptOperandVisitor);
                }
                else
                {
                    operand = replaceable.CastTo <T>();
                }
            }
        }
示例#5
0
        public static Operand <string> FuncToString <T>(this IOperand <T> obj)
        {
            var @operator = new UnaryOperators.OperatorCall <object>(s_ObjectToString);

            return(new UnaryExpressionOperand <object, string>(@operator, obj.CastTo <object>()));
        }
示例#6
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public HapilForShortSyntax For(IOperand <int> from, IOperand <int> to, int increment = 1)
        {
            return(new HapilForShortSyntax(this, from.CastTo <int>(), to.CastTo <int>(), increment));
        }