Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net System.Type的自定义属性参数_.net_Vb.net_Attributes_Custom Attributes - Fatal编程技术网

.net System.Type的自定义属性参数

.net System.Type的自定义属性参数,.net,vb.net,attributes,custom-attributes,.net,Vb.net,Attributes,Custom Attributes,我想在unity容器中自动注册公共/简单服务。我认为最干净的方法是使用一种定制的安眠药 然后,我可以检查程序集中的所有(抽象)类,并使用unity注册这些类型 我缺少的信息是类想要注册的接口 例如: 这个类将使用它,如下所示 <AutoRegister(ForInterface:=Stratego.Interfaces.IEngine)> Public Class StrategoEngine Implements IEngine Implements IDispos

我想在unity容器中自动注册公共/简单服务。我认为最干净的方法是使用一种定制的安眠药

然后,我可以检查程序集中的所有(抽象)类,并使用unity注册这些类型

我缺少的信息是类想要注册的接口

例如:

这个类将使用它,如下所示

<AutoRegister(ForInterface:=Stratego.Interfaces.IEngine)>
Public Class StrategoEngine
    Implements IEngine
    Implements IDisposable

    ...

End Class

公共级战略发动机
电子发动机
实现IDisposable
...
末级
注意,我不只是想找到它实现的任何类,如
IDisposable

我已经尝试过使用泛型(泛型不能从
属性
继承)和类型参数(传入IEngine.GetType会导致“常量表达式是必需的”)来实现这一点


这可能吗?如果是这样,我该如何实现它?

我不完全理解您想要实现什么,但我认为根据您的示例代码,您可以只放置一个空属性(类似于
)并使用它查找所有要注册的类。接口类型已由注册的类实现,因此您可以在运行时从类型中提取它。

如果可能,您只需编写:

<AutoRegister(ForInterface := GetType(Stratego.Interfaces.IEngine))>


问题在于,我不一定要针对它实现的所有接口注册它。谢谢,thaqt正是我想要的
<AutoRegister(ForInterface := GetType(Stratego.Interfaces.IEngine))>