复合属性属性

2023-09-05 04:17:30 作者:明人不放暗屁

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

例如,更改:

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

要:

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

解决方案

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

CSS

如果你控制了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...