Create a mustoveride function with code in it

I have a class MustInheritwith some MustOverideMethods. When I inherit the form of this class, I automatically get methods and properties MustOveride.

My question is what I want to be able to inherit from the class, get my functions and methods MustOveride, but then with some code that is already in it. I once saw a .net class that did this, when I inherited from this class, I got methods with some comments in it.

Does anyone have an idea what I mean? (A bit hard to describe ;-))

+3
source share
4 answers

, :
, , .
. , # VB.NET, IDE.

, , virtual (# - , VB.NET) .

+3

, , , :

 public abstract class MyClass
 {
      public void SomeMethod()
      {
           // code
           MustInherit();
           // code
      }

      protected abstract void MustInherit();
  }

, SomeMethod . , .

, , virtual.

 public abstract class MyClass
 {
      public void SomeMethod()
      {
           // code
           MustInherit();
           // code
      }

      protected virtual void CanInherit()
      {
           // default implementation
      }
  }
+9

: , , . , , .

0

virtual , . , .

, - " : base.MethodName(...);. all , .

, . , , .

Otherwise, if you want to see partially implemented methods with comments here and there, for example, Add your code here, this is usually a question of code generated by an external tool, such as Visual Studio or another IDE, and has nothing to do with the language itself.

But, as you can see, there are many possibilities, depending on you you want exactly ...

0
source

All Articles