title: Visibility of properties in derived classes (C#)
body: <p>I have been making some hamfisted attempts to apply correct OOP principles to my project.  I have an abstract class called DocumentSection, and several classes deriving from it (DocumentSectionView, DocumentSectionText, etc).  Similarly I have an abstract class (DocAction) with several classes deriving from it (DocumentActionReplaceByTag, DocumentSectionAppend, etc). Each DocumentSection has a DocumentAction within it.</p>
  
  <p>My understanding of all this inheritance business is that by specifying a 'DocumentAction', this would allow any of those derived classes to be put in its place, and that any properties/methods from the base class would be available, as well as any specified in the concrete class I instantiate.  So in the below example, I expected to be able to see the PerformAction method (leaving the virtual/override keywords out of the mix for now).  And it is available.</p>
  
  <p>However, because I went v.DocAction = new DocumentActionReplaceByTag();, I would also have expected my ReplaceActionFindText property to be visible.</p>
  
  <p>Obviously I've got it wrong somewhere - any comments appreciated.</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          DocumentSectionView v = new DocumentSectionView();
          v.DocAction = new DocumentActionReplaceByTag();
  
          // would like to go:
          //v.DocAction.ReplaceActionFindText...
  
          Console.ReadLine();
      }   
  }    
  public abstract class DocumentSection
  {
      public abstract string GetContent();
      public DocumentAction DocAction { get; set; }
  }
  public class DocumentSectionView : DocumentSection
  {
      public string ViewPath { get; set; }
      public dynamic ViewModel { get; set; }
  
      public override string GetContent()
      {
          return "test";
      }
  }    
  public abstract class DocumentAction
  {
      void PerformAction(StringBuilder sb, string content);
  }
  public class DocumentActionReplaceByTag : DocumentAction
  {
      public string ReplaceActionFindText { get; set; }
      public void PerformAction(StringBuilder sb, string content)
      {
          sb.Replace(ReplaceActionFindText, content);
      }
  }
  </code></pre>
  
  <p>EDIT:
  I've marked an answer as correct, but thought I'd add the fruits of my further thought on this matter for those coming across this later:</p>
  
  <p>a) As pointed out, my intentions were broadly right but my method wrong.  Setting the 'Action's property from the Main method was not correct.  In all cases, a a DocumentActionReplaceByTag requires the FindText so I placed it in the constructor:</p>
  
  <pre><code>    public DocumentActionReplaceByTag(string replaceActionFindText)
      {
          this.ReplaceActionFindText = replaceActionFindText;
      }
  </code></pre>
  
  <p>From then on, a constructor with 0 arguments will rightly fail, and prevent a case where the action is executed but no findtext is specified.</p>
  
  <p>b) Polymorphism works fine now, because my extra property findtext has been populated, and running PerformAction will run correctly regardless of the action type.</p>