private string CodeForBooleanAttribute(TagCodeGenerator tag) => IsBooleanAttribute() ? $@" /// <summary> /// Activate the {Key} attribute on the <{tag.TagName}> tag /// </summary> /// <returns>a {tag.ClassName} object to enable fluid command chaining</returns> {Method(tag.ClassName)}() => this.Attr(""{Key}"");" : null;
private string Method(TagCodeGenerator tag, string valueType) => $@" /// <summary> /// Set the {Key} attribute on the <{tag.TagName}> tag {CommentForPreprocessing} /// </summary> /// <param name=""value"">what should be in {Key}='...'. /// {SeparatorComment()}</param> /// <returns>a {tag.ClassName} object to enable fluid command chaining</returns> {Method(tag.ClassName)}({valueType} value) => this.Attr(""{Key}"", {ValuePreprocessor("value")}{GetSeparator()});";
public string Code(TagCodeGenerator tag) { var valueType = Type; var allMethods = new[] { MethodString(tag), MethodTyped(tag, valueType), // optional second signature with a int-type or something CodeForBooleanAttribute(tag), CodeForSrcSetAttribute(tag), "" // empty, to ensure trailing enters in generated code }; return(string.Join("\n\n", allMethods.Where(sc => sc != null))); }
private string CodeForSrcSetAttribute(TagCodeGenerator tag) => Key != "srcset" ? null : $"{Method(tag.ClassName)}(int multiplier, string name) => {Name}(name + \" \" + multiplier + (multiplier > 8 ? \"w\" : \"x\"));";
private string CodeForBooleanAttribute(TagCodeGenerator tag) => IsBooleanAttribute() ? $"{Method(tag.ClassName)}() => this.Attr(\"{Key}\");" : null;
private string MethodTyped(TagCodeGenerator tag, string type) => type == DefaultType ? "" : Method(tag, type);
private string MethodString(TagCodeGenerator tag) => Method(tag, DefaultType);
private string Method(TagCodeGenerator tag, string valueType) => $"{Method(tag.ClassName)}({valueType} value) => this.Attr(\"{Key}\", value{GetSeparator()});";