本文整理汇总了C#中StringBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.Add方法的具体用法?C# StringBuilder.Add怎么用?C# StringBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetJavaScriptResource
public static FilePathResult GetJavaScriptResource(this Assembly resourceAssembly, string controllerName, string resourceName)
{
var cachedJavaScriptFile = string.Format("~/{0}/Resources/{1}/{2}.{3}.js", WebAppConfig.AppCacheDirectory, controllerName, resourceName, System.Threading.Thread.CurrentThread.CurrentUICulture.Name);
var physicalPath = HttpContext.Current.Server.MapPath(cachedJavaScriptFile);
if (!File.Exists(physicalPath))
{
var requestedType = resourceAssembly.GetTypes().SingleOrDefault(x => x.FullName.EndsWith(controllerName + "." + resourceName));
if (requestedType == null)
{
throw new FileNotFoundException();
}
var sb = new StringBuilder();
sb.Add("if (typeof Views == 'undefined')");
sb.Add(" window.Views = Views = {};");
sb.Add("if (typeof Views.{0} == 'undefined')", controllerName);
sb.Add(" window.Views.{0} = Views.{0} = {{}};", controllerName);
sb.Add("if (typeof Views.{0}.{1} == 'undefined')", controllerName, resourceName);
sb.Add(" window.Views.{0}.{1} = Views.{0}.{1} = ", controllerName, resourceName);
sb.Add(" {");
var properties = requestedType.GetProperties();
for (var i = 0; i < properties.Length; i++)
{
if (properties[i].CanRead)
{
sb.Add(" {0} : {1}{2}", properties[i].Name, properties[i].GetValue(null, null).ToEscapeString(), ((i == properties.Length - 1) ? "" : ","));
}
}
sb.Add(" };");
sb.Add("var {1} = Views.{0}.{1};", controllerName, resourceName);
WriteFileContent(physicalPath, sb.ToString());
}
else
{
#if DEBUG
File.Delete(physicalPath);
#endif
}
return new FilePathResult(cachedJavaScriptFile, "application/x-javascript");
}
示例2: ToString
public string ToString(bool pretty = false)
{
var sb = new StringBuilder();
//sb.Add(@"<?xml version=""1.0"" encoding=""utf-8""?>", pretty);
var currentDepth = -1; // start at the same indenting as the <?xml..?> decalration
Action<IXmlElement> recurse = null;
recurse = e =>
{
currentDepth++;
if (e is CDataElement)
{
sb.Add("<![CDATA[ " + e.Value + " ]]>", pretty, currentDepth--);
return;
}
var xe = e as XmlElement;
if (xe == null)
return;
if (xe.Value == null && xe.Children.Count == 0)
{
sb.Add("<" + xe.Name + GetAttributes(xe) + " />", pretty, currentDepth);
}
else
{
// we keep text values on the same line, so only make it pretty if we don't have a value
sb.Add("<" + xe.Name + GetAttributes(xe) + ">", pretty && xe.Value == null, currentDepth);
if (xe.Value != null)
sb.Add(e.Value);
else
foreach (var child in xe.Children)
recurse(child);
sb.Add("</" + xe.Name + ">", pretty, xe.Value != null ? 0 : currentDepth);
}
currentDepth--;
};
recurse(RootElement);
return pretty ? sb.ToString().Trim() : sb.ToString().Replace("\t", "");
}
示例3: Create
private void Create(string targetControlId)
{
var script = new StringBuilder();
script.AppendFormat("{0} = window.{0} = popupMenu('{0}'", Id);
if (MinWidth > 0)
script.AppendFormat(", {0}", MinWidth);
script.Add(");");
foreach (var mi in Items)
{
mi.PrepareScript(this, script);
}
script.Add();
HiggsScriptManager.InsertScript("_" + targetControlId, "_" + Id, script.ToString());
}
示例4: ToString
public override string ToString()
{
var sb = new StringBuilder();
sb.Add("<div {0} class='RibbonGroup'>", !String.IsNullOrEmpty(Id) ? "id='" + Id + "'" : string.Empty);
sb.Add("<div class='content'>");
foreach(var c in Controls.Where(x => x.IsVisible))
{
sb.Add(c.ToString());
}
sb.Add("</div>");
sb.Add("<div class='GroupName'>{0}</div>", Title);
sb.Add("</div>");
return sb.ToString();
}
示例5: Create
public static MvcHtmlString Create(int runningScriptDelay = 0)
{
var sb = new StringBuilder();
if (RequiredScript != null)
{
foreach (var scriptPath in RequiredScript)
{
sb.Add("<script type=\"text/javascript\" src=\"{0}\"></script>", VirtualPathUtility.ToAbsolute(scriptPath, HttpContext.Current.Request.ApplicationPath));
}
RequiredScript = new List<string>();
}
if (RequiredStyleSheet != null)
{
foreach (var styleSheetPath in RequiredStyleSheet)
{
sb.Add("<link rel=\"Stylesheet\" href=\"{0}\">", VirtualPathUtility.ToAbsolute(styleSheetPath, HttpContext.Current.Request.ApplicationPath));
}
RequiredStyleSheet = new List<string>();
}
sb.Add();
var oldLength = sb.Length;
var hasScript = false;
sb.Add("<script type=\"text/javascript\">");
sb.Add("$(function()");
sb.Add("{");
if (runningScriptDelay > 0)
{
sb.Add("setTimeout(function()");
sb.Add("{");
}
if (Script != null)
{
if (Script.Length > 0)
{
sb.Add(Script.ToString());
Script = null;
hasScript = true;
}
}
if (GroupingScripts != null && GroupingScripts.Count > 0)
{
foreach (var script in GroupingScripts.OrderBy(x => x.Key))
{
sb.Add(script.Value.ToString());
}
GroupingScripts = null;
hasScript = true;
}
if(runningScriptDelay > 0)
{
sb.Add("}}, {0});", runningScriptDelay.ToString());
}
sb.Add("});");
sb.Add("</script>");
if(!hasScript)
{
sb = sb.Remove(oldLength, sb.Length - oldLength);
}
SerializedType = null;
return new MvcHtmlString(sb.ToString());
}
示例6: AddScript
// ReSharper restore MethodOverloadWithOptionalParameter
// ReSharper disable MethodOverloadWithOptionalParameter
public static void AddScript(string groupName, string script, params object[] args)
{
if (GroupingScripts == null)
GroupingScripts = new Dictionary<string, StringBuilder>();
if (GroupingScripts.ContainsKey(groupName))
{
GroupingScripts[groupName].Add(script, args);
}
else
{
var sb = new StringBuilder();
sb.Add(script, args);
GroupingScripts.Add(groupName, sb);
}
}