Skip to content

Instantly share code, notes, and snippets.

@jesuslpm
Created November 22, 2018 16:41
Show Gist options
  • Save jesuslpm/f93f9bcc4d3f3578cc97900a24339a34 to your computer and use it in GitHub Desktop.
Save jesuslpm/f93f9bcc4d3f3578cc97900a24339a34 to your computer and use it in GitHub Desktop.
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