本文整理汇总了C#中StringBuilder.AppendLineFormat方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendLineFormat方法的具体用法?C# StringBuilder.AppendLineFormat怎么用?C# StringBuilder.AppendLineFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.AppendLineFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseStatement
public string ParseStatement( PropertyInfo[] modelProperties, string sourceParamName)
{
var builder = new StringBuilder();
builder.AppendLineFormat("if(Take>0 || Skip>0)");
builder.AppendLine("{");
builder.AppendLineFormat("switch(OrderField)");
builder.AppendLine("{");
foreach (var modelProperty in modelProperties)
{
if (modelProperty.PropertyType.IsValueType || modelProperty.PropertyType == typeof (string))
{
builder.AppendLineFormat("case \"{0}\":", modelProperty.Name);
builder.AppendLineFormat(
"{0}=(OrderDirection==Agile.Common.Data.OrderDirection.ASC)?{0}.OrderBy(o=>o.{1}):{0}.OrderByDescending(o=>o.{1});", sourceParamName,
modelProperty.Name);
builder.AppendLine("break;");
}
}
builder.AppendLine("default:");
builder.AppendLineFormat(
"{0}=(OrderDirection==Agile.Common.Data.OrderDirection.ASC)?{0}.OrderBy(o=>o.{1}):{0}.OrderByDescending(o=>o.{1});", sourceParamName,
KeyPropertyName);
builder.AppendLine("break;");
builder.AppendLine("}");
builder.AppendLine("}");
return builder.ToString();
}
示例2: InitializeAutoComplete
public static string InitializeAutoComplete(this HtmlHelper html, string textBoxName, string fieldName, string url, object options, bool wrapInReady)
{
StringBuilder sb = new StringBuilder();
if (wrapInReady) sb.AppendLineFormat("<script language='javascript'>");
if (wrapInReady) sb.AppendLineFormat("$().ready(function() {{");
sb.AppendLine();
sb.AppendLineFormat(" $('#{0}').autocomplete('{1}', {{", textBoxName.Replace(".", "\\\\."), url);
PropertyInfo[] properties = options.GetType().GetProperties();
for (int i = 0; i < properties.Length; i++) {
sb.AppendLineFormat(" {0} : {1}{2}",
properties[i].Name,
properties[i].GetValue(options, null),
i != properties.Length - 1 ? "," : "");
}
sb.AppendLineFormat(" }});");
sb.AppendLine();
sb.AppendLineFormat(" $('#{0}').result(function(e, d, f) {{", textBoxName.Replace(".", "\\\\."));
sb.AppendLineFormat(" $('#{0}').val(d[1]);", fieldName);
sb.AppendLineFormat(" }});");
sb.AppendLine();
if (wrapInReady) sb.AppendLineFormat("}});");
if (wrapInReady) sb.AppendLineFormat("</script>");
return sb.ToString();
}
示例3: ParseStatement
public string ParseStatement(AnalyzeContext context)
{
Init();
/**
* ***Navigation
* if(concreteQuery.UserQuery != null)
* {
* {
* var naviQuery = concreteQuery.UserQuery;
* if(naviQuery.Id != null){
* source = source.Where(t=>t.User.Id == naviQuery.Id);
* }
* if(naviQuery.RoleQuery != null){
* var naviQuery_2 = naviQuery.RoleQuery;
*
* }
* }
* }
*/
if (context.Depth >= MaxDepth) return "";
var queryPropertyName = context.QueryProperty.Name;
var modelPropertyName = context.ModelProperty.Name;
var naviQueryParam = "naviQuery_" + (context.Depth + 1);
var builder = new StringBuilder();
builder.AppendLineFormat("if({0} != null)", context.QueryParamName+"."+queryPropertyName);
builder.AppendLine("{");
builder.AppendLineFormat("var {0}={1}.{2};", naviQueryParam, context.QueryParamName, queryPropertyName);
var naviQueryProperties = context.QueryProperty.PropertyType.GetProperties();
var naviModelProperties = context.ModelProperty.PropertyType.GetProperties();
foreach (var naviQueryProperty in naviQueryProperties)
{
var naviContext = new AnalyzeContext()
{
Depth = context.Depth + 1,
QueryProperty = naviQueryProperty,
SourceParamName = context.SourceParamName,
QueryParamName = naviQueryParam,
Navigations = context.Navigations.Concat(new[] {context.ModelProperty.Name}).ToArray()
};
for (var index = 0; index < Analyzers.Length; index++)
{
var naviAnalyzer = Analyzers[index];
var naviModelProperty = naviAnalyzer.FindAttachedModelProperty(naviQueryProperty, naviModelProperties);
if (naviModelProperty == null) continue;
naviContext.ModelProperty = naviModelProperty;
var naviStatement = naviAnalyzer.ParseStatement(naviContext);
queues[index].Add(naviStatement);
}
}
for (var index = 0; index < Analyzers.Length; index++)
{
builder.Append(string.Join("", queues[index]));
}
builder.AppendLine("}");
return builder.ToString();
}
示例4: AppendLineFormat
public void AppendLineFormat()
{
StringBuilder Builder=new StringBuilder();
Builder.AppendLineFormat("This is test {0}",1);
Assert.Equal("This is test 1" + System.Environment.NewLine, Builder.ToString());
Builder.Clear();
Builder.AppendLineFormat("Test {0}", 2)
.AppendLineFormat("And {0}", 3);
Assert.Equal("Test 2" + System.Environment.NewLine + "And 3" + System.Environment.NewLine, Builder.ToString());
}
示例5: GenerateQueryStatement
public string GenerateQueryStatement(Type queryType)
{
if (!TypeUtils.IsBaseEntityQuery(queryType))
{
throw new ArgumentException("not a valid query type", "queryType");
}
Type baseType = queryType.BaseType;
while (!baseType.IsGenericType)
{
baseType = baseType.BaseType;
}
var modelType = baseType.GetGenericArguments()[0];
if (!TypeUtils.IsBaseEntity(modelType))
{
throw new ArgumentException("generic type is not a valid model type", "queryType");
}
var queryProperties = queryType.GetProperties();
var modelProperties = modelType.GetProperties();
var builder = new StringBuilder();
builder.AppendLine("#region override DoQuery <auto-generated-code>");
builder.AppendLineFormat("public override IQueryable<{0}> {2}(IQueryable<{0}> {1})", modelType.Name, SourceParamName, QueryFuncName);
builder.AppendLine("{");
foreach (var queryProperty in queryProperties)
{
var context = new AnalyzeContext()
{
QueryProperty = queryProperty,
ModelType = modelType,
SourceParamName = SourceParamName,
QueryParamName = "this"
};
for (var index = 0; index < Analyzers.Length; index++)
{
var analyzer = Analyzers[index];
var modelProperty = analyzer.FindAttachedModelProperty(queryProperty, modelProperties);
if (modelProperty == null) continue;
context.ModelProperty = modelProperty;
var statment = analyzer.ParseStatement(context);
queues[index].Add(statment);
}
}
for (var index = 0; index < Analyzers.Length; index++)
{
builder.Append(string.Join("", queues[index]));
}
builder.Append(new PaginationAnalyzer().ParseStatement(modelProperties, SourceParamName));
builder.AppendLineFormat("return {0};", SourceParamName);
builder.AppendLine("}");
builder.AppendLine("#endregion");
return builder.ToString();
}
示例6: DumpGraph
public static void DumpGraph(string workingDirectory, Action<string> writer = null, int? maxCommits = null)
{
var output = new StringBuilder();
try
{
ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --format=""%h %cr %d"" --decorate --date=relative --all --remotes=*" + (maxCommits != null ? string.Format(" -n {0}", maxCommits) : null),
//@"log --graph --abbrev-commit --decorate --date=relative --all --remotes=*",
workingDirectory);
}
catch (FileNotFoundException exception)
{
if (exception.FileName != "git")
{
throw;
}
output.AppendLine("Could not execute 'git log' due to the following error:");
output.AppendLine(exception.ToString());
}
if (writer != null) writer(output.ToString());
else Trace.Write(output.ToString());
}
示例7: DumpGraph
public static void DumpGraph(this IRepository repository)
{
var output = new StringBuilder();
try
{
ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --abbrev-commit --decorate --date=relative --all --remotes=*",
repository.Info.Path);
}
catch (FileNotFoundException exception)
{
if (exception.FileName != "git")
throw;
output.AppendLine("Could not execute 'git log' due to the following error:");
output.AppendLine(exception.ToString());
}
Trace.Write(output.ToString());
}
示例8: ToString
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLineFormat("Id: {0}", Id);
sb.AppendLineFormat("FirstName: {0}", FirstName);
sb.AppendLineFormat("LastName: {0}", LastName);
sb.AppendLineFormat("EmailAddress: {0}", EmailAddress);
foreach (var language in Languages)
{
sb.AppendLineFormat("Language: {0}", language.LanguageCode);
}
sb.AppendLineFormat("Registration: {0}-{1}-{2}", RegistrationDate.Year, RegistrationNumber,
RegistrationSuffix);
return sb.ToString();
}
示例9: AppendLineFormat
public void AppendLineFormat()
{
// Type
var @this = new StringBuilder();
// Exemples
@this.AppendLineFormat("{0}{1}", "Fizz", "Buzz"); // return "FizzBuzz";
// Unit Test
Assert.AreEqual("FizzBuzz" + Environment.NewLine, @this.ToString());
}
示例10: ParseStatement
public string ParseStatement(AnalyzeContext context)
{
var queryPropertyName = context.QueryProperty.Name;
var modelPropertyName = context.ModelProperty.Name;
var navigation = new List<string>(context.Navigations) { modelPropertyName };
var builder = new StringBuilder();
builder.AppendLineFormat("if({0} != null)", context.QueryParamName + "." + queryPropertyName)
.AppendLine("{")
.AppendLineFormat("{0}={0}.Where(o=>o.{1}.Contains({2}));", context.SourceParamName, string.Join(".", navigation), context.QueryParamName + "." + queryPropertyName)
.AppendLine("}");
return builder.ToString();
}
示例11: ToConfigurationFile
public virtual string ToConfigurationFile()
{
StringBuilder sb = new StringBuilder();
Type type = this.GetType();
var props = type.GetProperties();
foreach (var prop in props)
{
sb.AppendLineFormat("{0}={1}", prop.Name, prop.GetValue(this, null));
}
return sb.ToString();
}
示例12: AppendLineFormatTestCase1
public void AppendLineFormatTestCase1()
{
var value0 = RandomValueEx.GetRandomString();
var sb = new StringBuilder();
sb.AppendLine( "Line 1" );
sb.AppendLineFormat( "Test: {0}", value0 );
sb.AppendLine( "Line 3" );
var expected = "Line 1\r\nTest: {0}\r\nLine 3\r\n".F( value0 );
var actual = sb.ToString();
Assert.AreEqual( expected, actual );
}
示例13: WriteOutputHeader
/// <summary>
/// Writes the output header.
/// </summary>
/// <param name="writer">The writer.</param>
/// <param name="programName">Name of the program.</param>
public void WriteOutputHeader(TextWriter writer, string programName)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(programName);
sb.AppendLine();
sb.AppendLineFormat("Today's Date: {0}", context.TodaysDate.ToString(Constants.DATE_FORMAT));
sb.AppendLineFormat("Start Date: {0}", context.StartDate.ToString(Constants.DATE_FORMAT));
sb.AppendLineFormat("Target End Date: {0}", context.TargetEndDate.ToString(Constants.DATE_FORMAT));
sb.AppendLineFormat("Balance: {0}", context.Balance.ToString("c"));
sb.AppendLineFormat("Interest Rate: {0}%", context.InterestRate.ToString("n2"));
sb.AppendLineFormat("Min. Repayment Amount: {0}", context.MinRepaymentAmount.ToString("c"));
sb.AppendLineFormat("Min. Repayment Day: {0}", context.MinRepaymentDay);
sb.AppendLineFormat("Extra Repayment Amount: {0}", context.ExtraRepaymentAmount.ToString("c"));
sb.AppendLineFormat("Extra Repayment Day: {0}", context.ExtraRepaymentDay);
sb.AppendLine();
sb.AppendLine();
writer.Write(sb.ToString());
}
示例14: DumpGraph
public static void DumpGraph(this IRepository repository)
{
var output = new StringBuilder();
ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --abbrev-commit --decorate --date=relative --all",
repository.Info.Path);
Trace.Write(output.ToString());
}
示例15: Generate
/// <summary>
/// Generates the specified assemblies using.
/// </summary>
/// <param name="assembliesUsing">The assemblies using.</param>
/// <param name="aspects">The aspects.</param>
/// <returns></returns>
public string Generate(List<Assembly> assembliesUsing, IEnumerable<IAspect> aspects)
{
var Builder = new StringBuilder();
Builder.AppendLineFormat(@"
public {0}()
{1}
{{
{2}
}}",
DeclaringType.Name + "Derived",
DeclaringType.IsInterface ? "" : ":base()",
aspects.ToString(x => x.SetupDefaultConstructor(DeclaringType)));
return Builder.ToString();
}