■ 함수형 확장을 사용하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
using System; /// <summary> /// 함수형 확장 /// </summary> public static class FunctionalExtension { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 함수 실행하기 - ExecuteFunction<TSource, TResult>(source, function) /// <summary> /// 함수 실행하기 /// </summary> /// <typeparam name="TSource">소스 타입</typeparam> /// <typeparam name="TResult">결과 타입</typeparam> /// <param name="source">소스</param> /// <param name="function">함수</param> /// <returns>결과</returns> public static TResult ExecuteFunction<TSource, TResult> ( this TSource source, Func<TSource, TResult> function ) => function(source); #endregion #region 액션 실행하기 - ExecuteAction<TSource>(source, action) /// <summary> /// 액션 실행하기 /// </summary> /// <typeparam name="TSource">소스 타입</typeparam> /// <param name="source">소스</param> /// <param name="action">액션</param> /// <returns>소스</returns> public static TSource ExecuteAction<TSource>(this TSource source, Action<TSource> action) { action(source); return source; } #endregion } |