Uploaded image for project: 'Etch'
  1. Etch
  2. ETCH-168

@ToString and inheritance

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.1
    • None
    • binding-csharp
    • None

    Description

      In inheritance tree of exceptions each exception has its GetMessage() method marked as 'new' which disables user from using polymorphism when having ancestor instance of ancestor exception cast to base type. Wouldn't it be better to use virtual GetMessage method on the base class and then have it overridden in ancestors?

      example:

      public class BaseException
      {
      public virtual string GetMessage()

      { return "Base exception message";}

      //currently
      //public string GetMessage()

      {...}
      }

      public class InheritedException : BaseException
      {
      public override string GetMessage() { return "Inhertied exception message";}

      //currently hiding the method from base class
      //public new string GetMessage(){...}

      }

      so then

      ((new InheritedException())as BaseException).GetMessage(); //would return "Inherited exception message"

      Attachments

        Activity

          People

            Unassigned Unassigned
            miksovic Michal Miksovic
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: