好吧,我有以下结构。基本上是一个插件架构如何获得类的名称
// assembly 1 - Base Class which contains the contract
public class BaseEntity {
public string MyName() {
// figure out the name of the deriving class
// perhaps via reflection
}
}
// assembly 2 - contains plugins based on the Base Class
public class BlueEntity : BaseEntity {}
public class YellowEntity : BaseEntity {}
public class GreenEntity : BaseEntity {}
// main console app
List<BaseEntity> plugins = Factory.GetMePluginList();
foreach (BaseEntity be in plugins) {
Console.WriteLine(be.MyName);
}
我想声明
be.MyName
告诉我对象是BlueEntity,YellowEntity或GreenEntity。重要的是MyName属性应该在基类中,因为我不想在每个插件中重新实现属性。
这是可能的C#?
这不正是提问是寻找(看看他添加到MyName方法中的注释问题) – hhafez 2008-12-03 23:00:20