我有一个使用属性的用户控件CollectionEditor
。我在同一个解决方案中使用另一个项目来测试控件。我的集合编辑器可以正常工作,除了 IDE 在我重新编译组件 dll 后在设计时给出错误。如果我关闭 IDE,而不是重新打开解决方案,它可以正常工作。如果我更改控件的代码并重新编译它,IDE 会给我同样的错误。我意识到如果我重新编译控件,IDE 不会为集合生成代码。但是如果我关闭并重新打开 IDE,它会生成代码。
错误信息:
属性“AProperty”的代码生成失败。错误是:'[A]MyComponent.AProperty 无法转换为 [B]MyComponent.AProperty。A 型源自 'MyComponent; Version=1.0.0.0,Culture=neutral,PublicKeyToken=null',位于位置 '...\AppData\Local\Microsoft\VCSExpress\10.0\ProjectAssemblies\1f88w0l001\MyComponent.dll' 的上下文 'LoadNeither' 中。B 型源自 'MyComponent; Version=1.0.0.0,Culture=neutral,PublicKeyToken=null' 在上下文 'LoadNeither' 的位置'...\AppData\Local\Microsoft\VCSExpress\10.0\ProjectAssemblies\eb4apk_301\MyComponent.dll'。
这是控件中的属性。
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ACollectionEditor), typeof(UITypeEditor))]
public ACollection AProperty { get { return prop; } }
以下是CollectionEditor
的代码:
public class ACollectionEditor : CollectionEditor
{
protected override object CreateInstance(Type itemType)
{
nameCounter++;
//var newObj = Activator.CreateInstance(itemType, new object[] { "AProperty" + nameCounter.ToString(), parent} );
var newObj = new AProperty("AProperty" + nameCounter.ToString());
return newObj;
}
}