好吧,我有以下結構。基本上是一個插件架構如何獲得類的名稱
// 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