/// <summary> /// Visit the given context and return a collection of the resultant contexts. /// </summary> /// <returns>Zero or more <see cref="IRenderingContext"/> instances, determined by the outcome of this visit.</returns> /// <param name="context">The rendering context to visit.</param> public override IRenderingContext[] Visit(IRenderingContext context) { if(context == null) { throw new ArgumentNullException(nameof(context)); } IZptAttribute attrib; if((attrib = context.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute)) != null) { context.MetalModel.AddGlobal(attrib.Value, context.Element); } return new [] { _macroExpander.ExpandMacros(context) }; }
/// <summary> /// Examines the given <see cref="IZptElement"/> and - if it has an attribute referencing another macro - gets that /// macro from the given <see cref="Model"/>. /// </summary> /// <returns>Either an <see cref="IZptElement"/> instance representing the referenced macro, or a <c>null</c> reference.</returns> /// <param name="context">The rendering context.</param> /// <param name="attributeName">The name of the desired attribute, which references a macro if present.</param> private IZptElement GetReferencedMacro(IRenderingContext context, string attributeName) { if(context == null) { throw new ArgumentNullException(nameof(context)); } IZptElement output; var attrib = context.GetMetalAttribute(attributeName); if(attrib != null) { ExpressionResult result; try { result = context.MetalModel.Evaluate(attrib.Value, context); output = result.GetValue<IZptElement>().Clone(); } catch(Exception ex) { string message = String.Format(Resources.ExceptionMessages.UnexpectedExceptionGettingMacro, attributeName, attrib.Value, context.Element.GetFullFilePathAndLocation()); throw new RenderingException(message, ex); } if(output == null) { string message = String.Format(Resources.ExceptionMessages.CannotFindMacro, attributeName, attrib.Value, context.Element.GetFullFilePathAndLocation()); throw new MacroNotFoundException(message); } } else { output = null; } return output; }