첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/// <summary>
/// 문자열 빌더 확장
/// </summary>
public static class StringBuilderExtension
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Static
    //////////////////////////////////////////////////////////////////////////////// Public

    #region 포맷 라인 추가하기 - AppendFormatLine(stringBuilder, format, argumentArray)

    /// <summary>
    /// 포맷 라인 추가하기
    /// </summary>
    /// <param name="stringBuilder">문자열 빌더</param>
    /// <param name="format">포맷 문자열</param>
    /// <param name="argumentArray">인자 배열</param>
    /// <returns>문자열 빌더</returns>
    public static StringBuilder AppendFormatLine
    (
        this StringBuilder stringBuilder,
        string             format,
        params object[]    argumentArray
    )
    => stringBuilder.AppendFormat(format, argumentArray).AppendLine();

    #endregion
    #region 특정 조건 해당시 추가하기 - AppendWhen(stringBuilder, predicateFunction, function)

    /// <summary>
    /// 특정 조건 해당시 추가하기
    /// </summary>
    /// <param name="stringBuilder">문자열 빌더</param>
    /// <param name="predicateFunction">판정 함수</param>
    /// <param name="function">함수</param>
    /// <returns>문자열 빌더</returns>
    public static StringBuilder AppendWhen
    (
        this StringBuilder                 stringBuilder,
        Func<bool>                         predicateFunction,
        Func<StringBuilder, StringBuilder> function
    )
    => predicateFunction() ? function(stringBuilder) : stringBuilder;

    #endregion
    #region 열거 가능형 추가하기 - AppendEnumerable<T>(stringBuilder, sourceEnumerable, function)

    /// <summary>
    /// 열거 가능형 추가하기
    /// </summary>
    /// <typeparam name="TItem">항목 타입</typeparam>
    /// <param name="stringBuilder">문자열 빌더</param>
    /// <param name="sourceEnumerable">소스 열거 가능형</param>
    /// <param name="function">누적 함수</param>
    /// <returns>문자열 빌더</returns>
    public static StringBuilder AppendEnumerable<TItem>
    (
        this StringBuilder                        stringBuilder,
        IEnumerable<TItem>                        sourceEnumerable,
        Func<StringBuilder, TItem, StringBuilder> function
    )
    => sourceEnumerable.Aggregate(stringBuilder, function);

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요