/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.Metal.MacroExpander"/> class. /// </summary> /// <param name="finder">A macro finder instance, or a null reference (in which case one will be constructed).</param> /// <param name="substituter">A substituter service for regular macro substitution, or a null reference (in which case one will be constructed).</param> /// <param name="extensionSubstitutor">A substituter service for macro extension, or a null reference (in which case one will be constructed).</param> public MacroExpander(IMacroFinder finder = null, IMacroSubstituter substituter = null, IMacroSubstituter extensionSubstitutor = null) { _macroFinder = finder?? new MacroFinder(); _normalSubstituter = substituter?? new MacroSubstituter(); _extensionSubstitutor = extensionSubstitutor?? new MacroExtensionSubstitutor(); }
/// <summary> /// Extends a given macro and then makes substitutions into the source context. /// </summary> /// <returns>The resultant rendering context after the substitutions are performed.</returns> /// <param name="context">The rendering context.</param> /// <param name="macro">The macro element to extend and use for substitutions.</param> /// <param name="macroStack">The collection of macros passed through to get to this point.</param> /// <param name="substitutionStrategy">The macro substitution strategy to use.</param> public virtual IRenderingContext ExtendAndSubstitute(IRenderingContext context, IZptElement macro, ref IList<IRenderingContext> macroStack, IMacroSubstituter substitutionStrategy) { if(context == null) { throw new ArgumentNullException(nameof(context)); } if(macro == null) { throw new ArgumentNullException(nameof(macro)); } if(macroStack == null) { throw new ArgumentNullException(nameof(macroStack)); } if(substitutionStrategy == null) { throw new ArgumentNullException(nameof(substitutionStrategy)); } var macroContext = context.CreateSiblingContext(macro); macroStack.Add(macroContext); var extendedContext = GetFullyExtendedContext(macroContext, ref macroStack); return substitutionStrategy.MakeSubstitutions(context, extendedContext, macroStack); }