Skip to content

Instantly share code, notes, and snippets.

@DavidArno
Created July 20, 2012 11:44
Show Gist options
  • Save DavidArno/3150305 to your computer and use it in GitHub Desktop.
Save DavidArno/3150305 to your computer and use it in GitHub Desktop.
Type<T> example
I have a class that is similar to:
public class SystemConfiguration<T1, T2, T3, T4, T5>
where T1 : ILogger, new()
where T2 : IReporter, new()
where T3 : IQueue, new()
where T4 : IConfiguration, new()
where T5 : ILauncher, new()
{
public SystemConfiguration()
{
var logger = new T1();
var queue = new T3();
var configuration = new T4();
var _systemPart1 = new SystemPart1(logger, configuration);
var _systemPart1 = new SystemPart2(queue, configuration);
....
What I want to do is:
public class SystemConfiguration
{
Type<T1> where T1 : ILogger, new() LoggerType { get; set; }
Type<T2> where T2 : IReporter, new() ReporterType { get; set; }
...
}
public class SystemSetup
{
public SystemSetup(SystemConfiguration systemConfiguration)
{
var logger = new systemConfiguration.LoggerType();
var reporter= new systemConfiguration.ReporterType();
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment