Ejemplo n.º 1
0
        /// <summary>
        /// Internal helper to create a replacement set based on the parent replacement set and a given entry identifier.
        /// </summary>
        internal static TemplateReplacementSet Create(TemplateReplacementSet parentReplacementSet, Guid entryIdentifier)
        {
            if (parentReplacementSet == null)
            {
                return(new TemplateReplacementSet());
            }

            TemplateReplacementSet        toReturn = new TemplateReplacementSet();
            List <TemplateReplacementSet> templateInstances;

            if (parentReplacementSet.ReplacementEntries.TryGetValue(entryIdentifier, out object list))
            {
                templateInstances = (List <TemplateReplacementSet>)list;
            }
            else
            {
                templateInstances = new List <TemplateReplacementSet>();
                parentReplacementSet.ReplacementEntries[entryIdentifier] = templateInstances;
            }
            templateInstances.Add(toReturn);
            return(toReturn);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to replace the token if it's available and returns true, otherwise returns false.
        /// </summary>
        /// <param name="templatePart">The template on which to replace the token.</param>
        /// <param name="tokenName">The name of the token.</param>
        /// <param name="replacementSet">The replacement set where to encode the value.</param>
        /// <param name="value">The value to encode.</param>
        /// <returns>True if was able to locate the token.</returns>
        public static bool TryReplaceToken(this ITemplatePart templatePart, string tokenName, TemplateReplacementSet replacementSet, object value)
        {
            if (templatePart.Tokens.TryGetValue(tokenName, out ITemplateToken templateToken))
            {
                templateToken.AssignValue(replacementSet, value);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
 public abstract void Write(string path, TemplateReplacementSet replacementSet);
 public void PrepareForReplacement(TemplateReplacementSet replacementSet)
 {
     Tokens.ForEach(t => t.PrepareForReplacement(replacementSet));
 }
 public void AssignValue(TemplateReplacementSet replacementSet, object value)
 {
     Tokens.ForEach(t => t.AssignValue(replacementSet, value));
 }