gpt4 book ai didi

c# - 装配体在设计时是如何解析的?

转载 作者:太空狗 更新时间:2023-10-30 01:28:02 25 4
gpt4 key购买 nike

我有一个带有 UITypeEditor 的可扩展性库(或一个的开始)。我现在想用 EditorAttribute 装饰属性。我不想引用扩展库,因为它不需要部署,所以我使用这个:

[Editor("MyProject.Extensibility.MyUIEditor, MyProject.Extensibility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", typeof (UITypeEditor))]
MySpecialType SpecialType { get; set; }

这行不通。类型编辑器用于枚举,当我使用它时,会显示标准枚举下拉列表。但是,如果将类型编辑器复制到项目中并使用直接类型引用,则一切正常。我已经尝试使用 Activator.CreateInstance 测试我的字符串并且我已经让它工作了。 MyProject.Extensibility.dll 被复制到几乎每个地方(所有项目的 bin/debug 文件夹)。是否有一些特殊的地方可以放置可扩展性 dll,以便 .net 可以解析程序集?

谢谢!

最佳答案

只需输入 Regedit.exe 并创建一个 key ,就像:

HKLM\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx\StackOverflow

It doesn't really matter what the name of the key is, all folder names listed within AssemblyFoldersEx are searched for Assemblies design-time by Visual Studio.

A folder must be added in Regedit using a (Default) entry having the folder path as value. (See sibling keys for example).

It's interesting that all folders present in the AssemblyFoldersEx registry key will automatically also appear when you click "Add New Reference" on a project context menu on the .NET tab.

Another approach would be to add the desired assembly to Global Access Cache (c:\Windows\Assembly)

I just made the following test: On a resource assembly I put the following code:

public class MyEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}

public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
{
MessageBox.Show("Works");
return null;
}
}

在消费者程序集(Windows 窗体可执行程序集)上,我创建了一个从 Button 派生的组件,就像这样:

public class MyButton : Button
{
[Editor("AssemblyReferenceCL.MyEditor, AssemblyReferenceCL", typeof(UITypeEditor))]
public String MyProp { get; set; }
}

两个程序集之间没有引用。一切正常。

关于c# - 装配体在设计时是如何解析的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1628264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com