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

标签 c# design-time

我有一个带有 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/

相关文章:

c# - asp.net MVC 4 外部登录提供程序 - 'No OpenID endpoint found' (google)

c# - 如何删除一条记录?

c# - 将实例的克隆分配给基本接口(interface)

wpf - 如何防止 d :DataContext binding 引起的设计时错误

c# - 将秒表转换为整数

c# - Collection of Collections 是否可能和/或最好的方式? C#.Net 3.5

c# - WPF 用户控件抛出设计时异常

delphi - 如何修复具有 TFont 属性的 Delphi 组件在设计时获取 "cannot assign NIL to a TFont"?

c# - 如何在构造函数中包含 Visual Studio 在设计时不会执行的代码?

delphi - 当选择多个项目时,为什么某些属性在对象检查器中隐藏?