Created
November 22, 2018 16:41
-
-
Save jesuslpm/f93f9bcc4d3f3578cc97900a24339a34 to your computer and use it in GitHub Desktop.
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 MessagePack; | |
using System; | |
using System.Diagnostics; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
namespace ConsoleApp | |
{ | |
public interface IS | |
{ | |
bool ShouldDoStuff { get; set; } | |
void MethodWithGeneric<T>(); | |
} | |
public interface MyService | |
{ | |
void AddPart(Action<IS> action); | |
} | |
public class SomeType { } | |
public class SomeOtherType { } | |
public static class Program | |
{ | |
static unsafe void Main() | |
{ | |
MyService myService = null; | |
myService.AddPart(s => | |
{ | |
s.ShouldDoStuff = true; | |
s.MethodWithGeneric<SomeType>(); | |
}); | |
myService.AddPart(s => | |
{ | |
s.ShouldDoStuff = false; | |
s.MethodWithGeneric<SomeOtherType>(); | |
}); | |
myService.AddPart<SomeType>(true); | |
myService.AddPart<SomeOtherType>(false); | |
} | |
public static void AddPart<T>(this MyService myService, bool shouldDoStuff ) | |
{ | |
myService.AddPart(s => | |
{ | |
s.ShouldDoStuff = shouldDoStuff; | |
s.MethodWithGeneric<T>(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment