Skip to content

Instantly share code, notes, and snippets.

@droyad
Created October 4, 2013 11:46
Show Gist options
  • Select an option

  • Save droyad/6824704 to your computer and use it in GitHub Desktop.

Select an option

Save droyad/6824704 to your computer and use it in GitHub Desktop.
namespace IBM
{
public class DeepThought
{
private static void Main(string[] args)
{
new DeepThought("What is the answer to life, the universe and everything?");
}
private DeepThought(Setting<QuestionConfigurationSetting, string> question)
{
}
}
public class QuestionConfigurationSetting
{
}
public class AnswerConfigurationSetting
{
}
public class Setting<TNamed, T>
{
public T Value { get; set; }
public static implicit operator T(Setting<TNamed, T> setting)
{
return setting.Value;
}
public static implicit operator Setting<TNamed, T>(T value)
{
return new Setting<TNamed, T>() {Value = value };
}
}
}
@droyad
Copy link
Author

droyad commented Oct 4, 2013

If you want to keep type safety:

public class QuestionConfigurationSetting : ISetting

public interface ISetting {}

public class Setting<TNamed, T> where TNamed : ISetting { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment