title: How to access methods in a parent class from the generic class?
body: <p>Here is what I am trying to do.</p>
  
  <p>To create a custom Html Helper with Fluent API, I have created this:</p>
  
  <pre><code>public interface IHelper:IHtmlString
  {
      IHelper AddClass(string className);
      IHelper Attributes(object htmlAttributes);
  }
  
  public class Helper : IHelper
  {
      private readonly Alert _parent;
  
      public Helper(Alert parent)
      {
          _parent = parent;
      }
  
      public string ToHtmlString()
      {
          return ToString();
      }
  
      public IHelper AddClass(string className)
      {
          return _parent.AddClass(className);
      }
  
      public IHelper Attributes(object htmlAttributes)
      {
          return _parent.Attributes(htmlAttributes);
      }
      public override string ToString()
      {
          return _parent.ToString();
      }
  }
  </code></pre>
  
  <p>The <code>Alert</code> class:</p>
  
  <pre><code>public interface IAlert : IHelper
  {
      IHelper HideCloseButton(bool hideCloseButton);
      IHelper Success();
      IHelper Warning();
  }
  
  public class Alert : IAlert
  {
      private readonly string _text;
      private AlertStyle _style;
      private  bool _hideCloseButton;
      private ICollection&lt;string&gt; _cssClass;
      private  object _htmlAttributes;
  
      public Alert(string text, AlertStyle style, bool hideCloseButton = false, object htmlAttributes = null)
      {
          _text = text;
          _style = style;
          _hideCloseButton = hideCloseButton;
          _htmlAttributes = htmlAttributes;
      }
      public override string ToString()
      {
          return "";
      }
  
      public string ToHtmlString()
      {
          return RenderAlert();
      }
      // private method RenderAlert() is omitted here.
  
      public IHelper AddClass(string className)
      {
          if (_cssClass == null) _cssClass = new List&lt;string&gt;();
          _cssClass.Add(className);
          return new Helper(this);
      }
  
      public IHelper Attributes(object htmlAttributes)
      {
          _htmlAttributes = htmlAttributes;
          return new Helper(this);
      }
  
      public IHelper HideCloseButton(bool hideCloseButton)
      {
          _hideCloseButton = hideCloseButton;
          return new Helper(this);
      }
  
      public IHelper Success()
      {
          _style = AlertStyle.Success;
          return new Helper(this);
      }
  
      public IHelper Warning()
      {
          _style = AlertStyle.Warning;
          return new Helper(this);
      }
  }
  </code></pre>
  
  <p>The problem is the constructor of my <code>Helper</code> class directly access the <code>Alert</code>. Then it is difficult to change my <code>IHelper</code> and <code>Helper</code> into generic <code>IHelper&lt;T&gt;</code> and <code>Helper&lt;T&gt;</code> to use for my other custom helpers like <code>DropDownList</code> and <code>CheckBoxGroup</code>.</p>
  
  <p>Since <code>AddClass</code> and <code>Attributes</code> methods should be available to all other Html helpers, I definitely don't want to have duplicate code. But what is the correct way to write this generic class? </p>