Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GenericMadness {
- public abstract class Module<T>
- where T : class, new()
- {
- protected Module ()
- {
- Populate ();
- }
- protected virtual void Populate ()
- {
- }
- public void AddAttribute<U> (string name, Func<T, U> getter)
- {
- ;
- }
- }
- public abstract class Foo {
- public double Number {
- get; set;
- }
- }
- public class Bar : Foo {
- public string Name {
- get; set;
- }
- }
- public abstract class FooModule<T> : Module<T>
- where T : Foo, new()
- {
- protected override void Populate ()
- {
- AddAttribute ("number", i => i.Number);
- base.Populate ();
- }
- }
- public class TestModule : FooModule<Bar>
- {
- protected override void Populate ()
- {
- AddAttribute ("test", i => i.Name);
- base.Populate ();
- }
- }
- public static void Run ()
- {
- new TestModule ();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement