public static PropertyValueTemplate AddProperty(this AnonymousObjectTemplate template, string name, ICodeFragment value = null) { PropertyValueTemplate propertyValueTemplate = new PropertyValueTemplate(name, value); template.Properties.Add(propertyValueTemplate); return(propertyValueTemplate); }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { AnonymousObjectTemplate template = (AnonymousObjectTemplate)fragment; output.Add("{") .Indent(); PropertyValueTemplate last = template.Properties.LastOrDefault(); foreach (PropertyValueTemplate property in template.Properties) { output.Add($"{property.Name}: ") .Add(property.Value) .If(property != last).Add(",").EndIf() .BreakLine(); } output.UnIndent().Add("}"); }
public static AnonymousObjectTemplate WithProperty(this AnonymousObjectTemplate template, string name, ICodeFragment value = null) { template.AddProperty(name, value); return(template); }