첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ Lazy<T> 클래스 : 변환 함수를 사용해 지연 객체 변환하기 예제

using System;

Lazy<double> resultLazy = Convert<int, double>(new Lazy<int>(() => 100), x => x * 2.0);

Console.WriteLine(resultLazy.Value);

 

728x90

 

▶ Lazy<T> 클래스 : 변환 함수를 사용해 지연 객체 변환하기

using System;

#region 변환하기 - Convert<TSource, TTarget>(sourceLazy, convertFunction)

/// <summary>
/// 변환하기
/// </summary>
/// <typeparam name="TSource">소스 타입</typeparam>
/// <typeparam name="TTarget">타겟 타입</typeparam>
/// <param name="sourceLazy">소스 지연 객체</param>
/// <param name="convertFunction">변환 함수</param>
/// <returns>타겟 지연 객체</returns>
public Lazy<TTarget> Convert<TSource, TTarget>
(
    Lazy<TSource>          sourceLazy,
    Func<TSource, TTarget> convertFunction
)
where TSource : struct
where TTarget : struct
{
    return new Lazy<TTarget>
    (
        () =>
        {
            TSource sourceValue = sourceLazy.Value;

            TTarget targetValue = convertFunction(sourceValue);

            return targetValue;
        }
    );
}

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

댓글을 달아 주세요