-
-
Save dimitris-papadimitriou-chr/f5ade388a4e6b64fb1a9dbf0ab084756 to your computer and use it in GitHub Desktop.
SimpleRefactorings.Medium.Decorator1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Threading.Tasks; | |
namespace FunctionalExperimentation.SimpleRefactorings.Medium.Decorator1 | |
{ | |
public static partial class FuntionalExtensions | |
{ | |
/// <summary> | |
/// Adds a debug loggin on the Task Result. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="this"></param> | |
/// <returns></returns> | |
public static Task<T> AddDebugLogging<T>(this Task<T> @this) => | |
@this.ContinueWith(continuationFunction: (task) => | |
{ | |
var result = task.Result; | |
Debug.WriteLine(result); | |
return result; | |
}); | |
public static Task<T> AddDebugLogging<T>(this Task<T> @this, Action<T> action) => | |
@this.ContinueWith(continuationFunction: (task) => | |
{ | |
var result = task.Result; | |
action(result); | |
return result; | |
}); | |
} | |
public class OperationManager<T, R> | |
{ | |
public async Task<R> OperationAsync(T t) => default(R); | |
} | |
public class Example | |
{ | |
public static async Task RunAsync() | |
{ | |
var operationManager = new OperationManager<int, string>(); | |
var result = await operationManager.OperationAsync(1) | |
.AddDebugLogging(); | |
var result1 = await operationManager.OperationAsync(1) | |
.AddDebugLogging(x => Debug.WriteLine(x)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment