Defining a subclass assembly by a method in a base class

Say I have a base class in Assembly A:

public class MyBaseClass{
    public static Assembly GetMyAssembly(){
     //determine the Assembly of my subclasses
    }
}

Then I subclass this class in assembly B:

public class MySubClass : MyBaseClass {
}

From there, in my specific logic of my domain, I call MySubClass.GetMyAssembly (). This logic can be in the same assembly as MySubClass, or it can be in a separate assembly. How to define an assembly containing a subclass that calls an inherited method? (without overriding) I tried to use various Assembly.Get * () methods in System.Reflection without any luck.

+3
source share
2 answers

You can not. This static method actually works in an assembly that has a base type.

, , ( ), . this.GetType() . Assembly , .

+1

Assembly.Get*() Type - :

this.GetType().BaseType.Assembly;

, typeof(MyBaseClass).Assembly - , , ,

0

Source: https://habr.com/ru/post/1759888/


All Articles