??????????????StringBuilder??????????????
???????????????????????????select?????????
private static string BuilderSelectBox(IDictionary<int?? string> options?? string id?? bool includeUnknown)
{
var html = new StringBuilder();
html.AppendFormat("<select id="{0}" name="{0}">"?? id);
html.AppendLine();
if(includeUnknown)
{
html.AppendLine(" <option>Unknown</option>");
}
foreach(var opt in options)
{
html.AppendFormat(" <option value="{0}">{1}</option>"?? opt.Key?? opt.Value);
html.AppendLine();
}
html.AppendLine("</select>");
return html.ToString();
}
?????????
????html.AppendFormat("<select id="{0}" name="{0}">"?? id);
????html.AppendLine();
?????????????????????????StringBuilder??
???????
public static class StringBuilderExtensions
{
public static StringBuilder AppendFormattedLine(this StringBuilder @this?? string format?? prams object[] args) => @this.AppendFormat(format?? args).AppendLine();
}
private static string BuilderSelectBox(IDictionary<int?? string> options?? string id?? bool includeUnknown)
{
var html = new StringBuilder()
.AppendFormattedLine("<select id="{0}" name="{0}">"?? id);
if(includeUnknown)
{
html.AppendLine(" <option>Unknown</option>");
}
foreach(var opt in options)
{
html.AppendFormattedLine(" <option value="{0}">{1}</option>"?? opt.Key?? opt.Value);
html.AppendLine();
}
html.AppendLine("</select>");
return html.ToString();
}
?????????
????if(includeUnknown)
????{
????html.AppendLine(" <option>Unknown</option>");
????}
??????????????????з???????????StringBuilder.
public static class StringBuilderExtensions
{
public static StringBuilder AppendFormattedLine(this StringBuilder @this?? string format?? prams object[] args) => @this.AppendFormat(format?? args).AppendLine();
public static StringBuilder AppendLineWhen(this StringBuilder @this?? Func<bool> predicate?? string value) =>
predicate()
? @this.AppendLine(value)
: @this;
}
private static string BuilderSelectBox(IDictionary<int?? string> options?? string id?? bool includeUnknown)
{
var html = new StringBuilder()
.AppendFormattedLine("<select id="{0}" name="{0}">"?? id)
.AppendLineWhen(() => includeUnknown?? " <option>Unknown</option>");
foreach(var opt in options)
{
html.AppendFormattedLine(" <option value="{0}">{1}</option>"?? opt.Key?? opt.Value);
}
html.AppendLine("</select>");
return html.ToString();
}