title: Giving base class access to child-class variables without getter and setter methods
body: <p>The base class <code>MasterClass</code> holds a Dictionary containing a <code>string</code> key and a <code>HookObj</code> value, where <code>HookObj</code> holds (from the derived class) the variable Type, and reference to it's get/set methods.</p>
  
  <p>Now when the base class <code>MasterClass</code> receives data from some source, it will cast/assign it like so:</p>
  
  <pre><code>//Data came in from an external source, see if we know what variable to assign the value to
  public void receiveData(string key, string value)
  {
      if (dict.ContainsKey(key))
          assignVal(dict[key], value);
      else
          throw new NotImplementedException(); //use NotImplementedException as placeholder until we make proper exception
  }
  
  //Cast the value-string to the proper type and assign it
  private void assignVal(HookObj hookobj, string value)
  {
      try
      {
          if (hookobj.theType == typeof(string))
              hookobj.setMethod(value);
          else if (hookobj.theType == typeof(int))
              hookobj.setMethod(Int32.Parse(value));
          else if (hookobj.theType == typeof(float))
              hookobj.setMethod(float.Parse(value));
          else
              throw new NotImplementedException();
      }
      catch (RuntimeBinderException ex) { throw new NotImplementedException("", ex); }
      catch (System.FormatException ex) { throw new NotImplementedException("", ex); }
  }
  </code></pre>
  
  <p>With <code>HookObj</code> being:</p>
  
  <pre><code>internal class HookObj
  {
      public Type theType { get; private set; }
      public Action&lt;dynamic&gt; setMethod { get; private set; }
      public Func&lt;dynamic&gt; getMethod { get; private set; }
  
      public HookObj(Type theType, Action&lt;dynamic&gt; setMethod, Func&lt;dynamic&gt; getMethod)
      {
          this.theType = theType;
          this.setMethod = setMethod;
          this.getMethod = getMethod;
      }
  }
  </code></pre>
  
  <p>Use of the getter methods shouldn't need explenation. So now let's see how messy this becomes for the end user:</p>
  
  <pre><code>class Attachvariable : MasterClass
  {
      public Attachvariable(int id) : base(id) { }
      public Attachvariable(int userID, string position)
          : base()
      {
          this.userID = userID;
          this.position = position;
      }
  
      int userID;
      string position;
  
      protected override void hookMethod()
      {
          newHookAndAdd(typeof(int), set_userID, get_userID, "userID").
          newHookAndAdd(typeof(string), set_position, get_position, "position");
      }
  
      public void set_userID(dynamic theVal)
      {
          userID = theVal;
      }
      public void set_position(dynamic theVal)
      {
          position = theVal;
      }
  
      public dynamic get_userID()
      {
          return userID;
      }
      public dynamic get_position()
      {
          return position;
      }
  }
  </code></pre>
  
  <p>Where I was hoping it to be more like this:</p>
  
  <pre><code>protected override void hookMethod()
  {
      newHookAndAdd(ref userID, "userID");
      //etc
  }
  </code></pre>
  
  <p>But it's not possible to store references for later use it seems.. is there any way to make this more user friendly? Creating two functions per variable is going to get really messy I'd guess.</p>