我今年寫了這個早期的解決方案:Components和ComponentEntities
組件之間的關係是通過註解屬性和方法定義,如所見here:
// Link to component of type B through a property.
// The name doesn't matter.
[ComponentLink]
B B { get; set; }
// Called when components are added or removed.
// The parameter type acts as a filter.
[NotifyComponentLinked]
void Added(object o)
{ Console.WriteLine(this.GetType().Name + " linked to " + o.GetType().Name + "."); }
[NotifyComponentUnlinked]
void Removed(object o)
{ Console.WriteLine(this.GetType().Name + " unlinked from " + o.GetType().Name + "."); }
// Attaches to events in compenents of type D and E.
// Rewriting this with Lambda Expressions may be possible,
// but probably would be less concise due to lack of generic attributes.
//
// It should be possible to validate them automatically somehow, though.
[EventLink(typeof(D), "NumberEvent")]
[EventLink(typeof(E), "NumberEvent")]
void NumberEventHandler(int number)
{ Console.WriteLine("Number received by F: " + number); }
ComponentEntities項目包含集合,這些集合將自己添加爲自己或添加到其中的實體的組件,以避免全局單例。如果你想要一個帶有Components和ComponentsTest(用法示例)項目的VS解決方案,請克隆bundle repository。
組件的許可證是LGPL,目前爲止我沒有授權使用ComponentEntities(我剛剛將存儲庫設置爲公共),但是如果您需要,您可以在大約10分鐘內寫出與我上面所寫內容相同的內容。
請嘗試閱讀本文http://stackoverflow.com/help/deleted-answers,以獲得更多瞭解如何**不**回答。即:「不能從根本上回答問題的答案」:**僅僅是一個鏈接到外部網站** –