public object @foreach( object objToEnumerate, string macroToCall, params object [] extraArgs ) { // ****** if( null == objToEnumerate ) { ThreadContext.MacroError( "$.foreach requires an object to iterate over as its first argument" ); } // ****** if( string.IsNullOrEmpty(macroToCall) ) { ThreadContext.MacroError( "$.foreach requires the name of a macro to invoke" ); } // ****** var handler = new ForeachHandler( mp ); if( '!' == macroToCall[0] || '&' == macroToCall[0] ) { return handler.Foreach_TextChunk( objToEnumerate, macroToCall.Substring(1), extraArgs ); } // ****** IMacro target; if( ! mp.FindMacro(macroToCall, out target) ) { ThreadContext.MacroError( "$.foreach could not locate the macro: \"{0}\"", macroToCall ); } // ****** if( MacroType.Text == target.MacroType ) { return handler.ForeachTextMacro( target, objToEnumerate, extraArgs ); } else { return handler.ForeachObjectMacro( target, objToEnumerate, extraArgs ); } }
///////////////////////////////////////////////////////////////////////////// // // (#foreach objToEnumerate [, `extraArgs'] ) // ///////////////////////////////////////////////////////////////////////////// public override object Evaluate( IMacro macro, IMacroArguments macroArgs ) { // ****** var args = GetMacroArgsAsTuples( macroArgs.Expression ) as NmpTuple<object, object[]>; object objToEnumerate = args.Item1; object [] extraArgs = args.Item2; // ****** if( null == objToEnumerate ) { ThreadContext.MacroError( "(#foreach ...) requires an object to iterate over as its first argument" ); } // ****** var handler = new ForeachHandler( mp ); return handler.Foreach_TextChunk( objToEnumerate, macroArgs.BlockText, extraArgs ); }