【发布时间】:2011-06-01 10:33:33
【问题描述】:
在我的项目中,我有两个库目前会导致我无法解决的循环依赖。
一个库为整个解决方案提供通用数据结构。这个库包含一个类似这样的结构:
namespace Common {
public class Foo {
//[Editor( typeof( UserEditor ), typeof( UITypeEditor ) )]
public UInt32 OwnerId { get; set; }
}
public class User {
public UInt32 Id { get; set; }
}
}
现在在我们解决方案中的一个项目中,我们想通过 PropertyGrid 编辑 Foo 实例,并且应该使用自定义编辑器编辑 OwnerId 属性;这个:
using Common;
namespace Common.Gui {
public class OwnerEditor : UITypeEditor {
public static List<User> Users { get; set; }
}
}
现在,我不能只将EditorAttribute 添加到Foo.OwnerId,因为这会产生循环依赖,而且我想保留对Common.Gui 的引用而不是Common。我还想避免将代码从 Common 拉到新程序集中,因为许多其他项目都引用它。
我发现了一个关于 adding EditorAttribute at runtime 的问题,这听起来像是一个完美的解决方案,但我无法熟练地解决我的问题。
【问题讨论】: