复合属性 [英] Composite Attribute

查看:386
本文介绍了复合属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让在C#复合属性在编译时提供相同的元数据?

例如,更改:

  [ClassInterface(ClassInterfaceType.AutoDual)
[的ProgId(MyProgId)]
[MyMefExport(MyProgId)]
公共类MyClass的
{
}
 

要:

  [MyCompositeAttribute(MyProgId)
公共类MyClass的
{
}
 

解决方案

属性的本身是没有意义的和。它是code,列举连接到一类,可能会改变其操作的属性。

如果你控制了code表示理解的属性,你可以创建一个复合的属性和行为,就好像多个单独的属性被应用。

话虽这么说,我怀疑你控制的ProgId < /一>,也不是C#编译器,国米$ P $点吧...

Is there any way of making a composite attribute in C# to provide equivalent metadata at compile time?

E.g, change:

[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("MyProgId")]
[MyMefExport("MyProgId")]
public class MyClass
{
}

To:

[MyCompositeAttribute("MyProgId")]
public class MyClass
{
}

解决方案

Attributes in and of themselves are meaningless. It is the code that enumerates the attributes attached to a class that may change its operation.

If you control the code that understands the attribute, you could create a composite attribute and act as though multiple separate attributes were applied.

That being said, I doubt you control ProgId nor the C# compiler that interprets it...

这篇关于复合属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆