C#属性集合 [英] C# attribute collection
问题描述
我有一定的收藏内置属性(如System.Runtime.Serialization.SerializableAttribute),我想申请到一定的集合类
I have a certain collection of built-in attributes (like System.Runtime.Serialization.SerializableAttribute) that I want to apply to a certain collection of classes
是否有可能联合这些属性为一体?我不想适用所有的人都来我所有的类的明确(的attibute集合可能在开发过程中改变)
Is it possible to unite those attributes into one? I don't want to apply all of them to all of my classes explicitly (the attibute collection might change during the development process)
我要的是一个属性,例如。
What I want is one attribute, e.g.
public class MyClassAttribute: System.Attribute { ... }
我可以很容易地应用到我的班
which I could apply easily to my classes
[MyClass]
public class SampleClass { ... }
这将导致SampleClass有Serializable属性等。谢谢
and that would cause SampleClass to have Serializable attribute and others. Thanks
推荐答案
没有,没有,基本上是这样。事实上, [Serializable接口]
是尤其的笔记值得,因为在编译器不同的待遇 - 这是不是写为一个属性,但作为原标志(在运行时只是在于,如果你问它有 [Serializable接口]
属性 - 它会针对该类型的标志,并返回你的期待的看到,尽管这不是真理)。
No, it is not, basically. Actually, [Serializable]
is particularly note-worthy because that has different treatment in the compiler - it is not written as an attribute, but as a raw flag (the runtime simply lies if you ask "does it have the [Serializable]
attribute" - it checks the flag against the type, and returns what you expect to see, even though that isn't the truth).
这篇关于C#属性集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!