Advertisement
baulig

Generic Madness

Jan 12th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1.     public class GenericMadness {
  2.  
  3.         public abstract class Module<T>
  4.             where T : class, new()
  5.         {
  6.             protected Module ()
  7.             {
  8.                 Populate ();
  9.             }
  10.  
  11.             protected virtual void Populate ()
  12.             {
  13.             }
  14.            
  15.             public void AddAttribute<U> (string name, Func<T, U> getter)
  16.             {
  17.                 ;
  18.             }
  19.         }
  20.  
  21.         public abstract class Foo {
  22.             public double Number {
  23.                 get; set;
  24.             }
  25.         }
  26.        
  27.         public class Bar : Foo {
  28.             public string Name {
  29.                 get; set;
  30.             }
  31.         }
  32.  
  33.         public abstract class FooModule<T> : Module<T>
  34.             where T : Foo, new()
  35.         {
  36.             protected override void Populate ()
  37.             {
  38.                 AddAttribute ("number", i => i.Number);
  39.                 base.Populate ();
  40.             }
  41.         }
  42.        
  43.         public class TestModule : FooModule<Bar>
  44.         {
  45.             protected override void Populate ()
  46.             {
  47.                 AddAttribute ("test", i => i.Name);
  48.                 base.Populate ();
  49.             }
  50.         }
  51.        
  52.         public static void Run ()
  53.         {
  54.             new TestModule ();
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement