Created
October 4, 2013 11:46
-
-
Save droyad/6824704 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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 }; | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to keep type safety:
public class QuestionConfigurationSetting : ISetting
public interface ISetting {}
public class Setting<TNamed, T> where TNamed : ISetting { ... }