当前位置: 首页>>代码示例>>C#>>正文


C# StringBuilder.AppendLineIf方法代码示例

本文整理汇总了C#中StringBuilder.AppendLineIf方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendLineIf方法的具体用法?C# StringBuilder.AppendLineIf怎么用?C# StringBuilder.AppendLineIf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringBuilder的用法示例。


在下文中一共展示了StringBuilder.AppendLineIf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRequestHeader

 //public static IEnumerable<Cookie> GetAllCookies(this CookieContainer cc)
 //{
 //    var table = (Hashtable)cc.GetType().InvokeMember("m_domainTable",
 //    BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance,
 //    null, cc, new object[] { });
 //    foreach (var pathList in table.Values)
 //    {
 //        var lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list",
 //        BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance,
 //        null, pathList, new object[] { });
 //        foreach (CookieCollection colCookies in lstCookieCol.Values)
 //        {
 //            foreach (var c in colCookies.OfType<Cookie>())
 //            {
 //                yield return c;
 //            }
 //        }
 //    }
 //}
 //public static IEnumerable<Cookie> GetCookies(this CookieContainer cc, string name)
 //{
 //    return GetAllCookies(cc).Where(item => string.Compare(item.Name, name, StringComparison.OrdinalIgnoreCase) == 0);
 //}
 public static string GetRequestHeader(this QQHttpRequest request, CookieContainer cc)
 {
     var sb = new StringBuilder();
     sb.AppendLineIf($"{HttpConstants.Referrer}: {request.Referrer}", !request.Referrer.IsNullOrEmpty());
     sb.AppendLineIf($"{HttpConstants.UserAgent}: {request.UserAgent}", !request.UserAgent.IsNullOrEmpty());
     sb.AppendLineIf($"{HttpConstants.ContentType}: {request.ContentType}", !request.ContentType.IsNullOrEmpty());
     var cookies = cc.GetCookies(new Uri(request.Url)).OfType<Cookie>();
     sb.AppendLine($"{HttpConstants.Cookie}: {string.Join("; ", cookies)}");
     return sb.ToString();
 }
开发者ID:huoshan12345,项目名称:iQQ.Net,代码行数:33,代码来源:HttpExtensions.cs

示例2: BuildTable

        /// <summary>
        /// Builds the SQL for the temporary table used in the merge operation.
        /// </summary>
        /// <param name="mergeDefinition">The merge definition.</param>
        /// <returns></returns>
        public static string BuildTable(DataMergeDefinition mergeDefinition)
        {
            var builder = new StringBuilder();
            builder
                .Append("CREATE TABLE ")
                .Append(TableIdentifier(mergeDefinition.TemporaryTable))
                .AppendLine()
                .Append("(")
                .AppendLine();

            bool hasColumn = false;
            foreach (var mergeColumn in mergeDefinition.Columns.Where(c => !c.IsIgnored))
            {
                bool writeComma = hasColumn;

                builder
                    .AppendLineIf(",", v => writeComma)
                    .Append(' ', TabSize)
                    .Append(QuoteIdentifier(mergeColumn.SourceColumn))
                    .Append(" ")
                    .Append(mergeColumn.NativeType)
                    .Append(" NULL");

                hasColumn = true;
            }

            builder
                .AppendLine()
                .Append(")")
                .AppendLine();

            return builder.ToString();
        }
开发者ID:modulexcite,项目名称:FluentCommand,代码行数:38,代码来源:DataMergeGenerator.cs

示例3: AppendLineIf

        public void AppendLineIf()
        {
            // Type
            var @this = new StringBuilder();

            // Exemples
            @this.AppendLineIf(x => x.Contains("F"), "Fizz", "Buzz"); // return "FizzBuzz";

            // Unit Test
            Assert.AreEqual("Fizz" + Environment.NewLine, @this.ToString());
        }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:11,代码来源:StringBuilder.AppendLineIf.cs

示例4: ToString

 public override string ToString()
 {
     var msg = new StringBuilder($"ErrorCode={ErrorCode}, ErrorMsg={this.GetAllMessages()}, StackTrace=");
     msg.AppendLineIf($"{Environment.NewLine}{StackTrace}", StackTrace != null);
     return msg.ToString();
 }
开发者ID:huoshan12345,项目名称:iQQ.Net,代码行数:6,代码来源:WeChatException.cs

示例5: BuildMerge

        /// <summary>
        /// Builds the SQL merge statement for the merge operation.
        /// </summary>
        /// <param name="mergeDefinition">The merge definition.</param>
        /// <returns></returns>
        public static string BuildMerge(DataMergeDefinition mergeDefinition)
        {
            var mergeColumns = mergeDefinition.Columns
                .Where(c => !c.IsIgnored)
                .ToList();

            var builder = new StringBuilder();

            if (mergeDefinition.IdentityInsert && mergeDefinition.IncludeInsert)
            {
                builder
                    .Append("SET IDENTITY_INSERT ")
                    .Append(TableIdentifier(mergeDefinition.TargetTable))
                    .AppendLine(" ON;")
                    .AppendLine();
            }


            builder
                .Append("MERGE INTO ")
                .Append(TableIdentifier(mergeDefinition.TargetTable))
                .Append(" AS t")
                .AppendLine()
                .AppendLine("USING")
                .AppendLine("(")
                .Append(' ', TabSize)
                .AppendLine("SELECT");

            bool hasColumn = false;
            foreach (var mergeColumn in mergeColumns)
            {
                bool writeComma = hasColumn;

                builder
                    .AppendLineIf(",", v => writeComma)
                    .Append(' ', TabSize * 2)
                    .Append(QuoteIdentifier(mergeColumn.SourceColumn));

                hasColumn = true;
            }

            builder
                .AppendLine()
                .Append(' ', TabSize)
                .Append("FROM ")
                .Append(TableIdentifier(mergeDefinition.TemporaryTable))
                .AppendLine()
                .AppendLine(")")
                .AppendLine("AS s")
                .AppendLine("ON")
                .AppendLine("(");

            hasColumn = false;
            foreach (var mergeColumn in mergeColumns.Where(c => c.IsKey))
            {
                bool writeComma = hasColumn;
                builder
                    .AppendLineIf(" AND ", v => writeComma)
                    .Append(' ', TabSize)
                    .Append("t.")
                    .Append(QuoteIdentifier(mergeColumn.TargetColumn))
                    .Append(" = s.")
                    .Append(QuoteIdentifier(mergeColumn.SourceColumn));

                hasColumn = true;
            }

            builder
                .AppendLine()
                .Append(")")
                .AppendLine();

            // Insert
            AppendInsert(mergeDefinition, builder);

            // Update
            AppendUpdate(mergeDefinition, builder);

            // Delete
            AppendDelete(mergeDefinition, builder);

            // Output
            AppendOutput(mergeDefinition, builder);

            // merge must end with ;
            builder.Append(";");

            if (mergeDefinition.IdentityInsert && mergeDefinition.IncludeInsert)
            {
                builder
                    .Append("SET IDENTITY_INSERT ")
                    .Append(TableIdentifier(mergeDefinition.TargetTable))
                    .AppendLine(" OFF;")
                    .AppendLine();
            }
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:FluentCommand,代码行数:101,代码来源:DataMergeGenerator.cs

示例6: AppendInsert

        private static void AppendInsert(DataMergeDefinition mergeDefinition, StringBuilder builder)
        {
            if (!mergeDefinition.IncludeInsert)
                return;

            var mergeColumns = mergeDefinition.Columns
                .Where(c => !c.IsIgnored && c.CanInsert)
                .ToList();

            builder
                .AppendLine("WHEN NOT MATCHED BY TARGET THEN ")
                .Append(' ', TabSize)
                .AppendLine("INSERT")
                .Append(' ', TabSize)
                .AppendLine("(");

            bool hasColumn = false;
            foreach (var mergeColumn in mergeColumns)
            {
                bool writeComma = hasColumn;
                builder
                    .AppendLineIf(",", v => writeComma)
                    .Append(' ', TabSize * 2)
                    .Append(QuoteIdentifier(mergeColumn.TargetColumn));

                hasColumn = true;
            }
            builder.AppendLine();

            builder
                .Append(' ', TabSize)
                .AppendLine(")")
                .Append(' ', TabSize)
                .AppendLine("VALUES")
                .Append(' ', TabSize)
                .AppendLine("(");

            hasColumn = false;
            foreach (var mergeColumn in mergeColumns)
            {
                bool writeComma = hasColumn;
                builder
                    .AppendLineIf(",", v => writeComma)
                    .Append(' ', TabSize * 2)
                    .Append("s.")
                    .Append(QuoteIdentifier(mergeColumn.SourceColumn));

                hasColumn = true;
            }
            builder.AppendLine();

            builder
                .Append(' ', TabSize)
                .AppendLine(")");
        }
开发者ID:modulexcite,项目名称:FluentCommand,代码行数:55,代码来源:DataMergeGenerator.cs

示例7: AppendUpdate

        private static void AppendUpdate(DataMergeDefinition mergeDefinition, StringBuilder builder)
        {
            if (!mergeDefinition.IncludeUpdate)
                return;

            var mergeColumns = mergeDefinition.Columns
                .Where(c => !c.IsIgnored && c.CanUpdate)
                .ToList();

            builder
                .AppendLine("WHEN MATCHED THEN ")
                .Append(' ', TabSize)
                .AppendLine("UPDATE SET");

            bool hasColumn = false;
            foreach (var mergeColumn in mergeColumns)
            {
                bool writeComma = hasColumn;
                builder
                    .AppendLineIf(",", v => writeComma)
                    .Append(' ', TabSize * 2)
                    .Append("t.")
                    .Append(QuoteIdentifier(mergeColumn.TargetColumn))
                    .Append(" = s.")
                    .Append(QuoteIdentifier(mergeColumn.SourceColumn));

                hasColumn = true;
            }
            builder.AppendLine();
        }
开发者ID:modulexcite,项目名称:FluentCommand,代码行数:30,代码来源:DataMergeGenerator.cs


注:本文中的StringBuilder.AppendLineIf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。