C#属性集合属性

由网友(艹蛋的青春じ让我蛋疼ミ)分享简介:我有一定的收藏内置属性(如System.Runtime.Serialization.SerializableAttribute),我想申请到一定的集合类I have a certain collection of built-in attributes (like System.Runtime.Serializati...

我有一定的收藏内置属性(如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有Seri​​alizable属性等。谢谢

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).

阅读全文

相关推荐

最新文章