//----------------------------------------------------------------------------------------------------------------------------------------------------- #region IMutableOperand Members IOperand IMutableOperand.Assign(IOperand value) { if (value is IOperand <T> ) { return(Assign((IOperand <T>)value)); } else { return(Assign(value.CastTo <T>())); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- #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); }); }); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- #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); }); }); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- 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>(); } } }
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>())); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public HapilForShortSyntax For(IOperand <int> from, IOperand <int> to, int increment = 1) { return(new HapilForShortSyntax(this, from.CastTo <int>(), to.CastTo <int>(), increment)); }