Is there any difference between decorating / decorating names and decorating attributes?

I was reading a text about expanding to C # and at one point it says that "Decorating an X attribute can only be applied to fields of type Y".

I have not been able to find a definition for decorating attributes, and I am not very clear about it, exchanging two.

+1


source to share


2 answers


This probably refers to the attribute class. For example, you can mark a type as serializable via SerializableAttribute. When you apply an attribute, you can leave the suffix "Attribute".

[Serializable]
public class SomeClass {

}

      



Attributes provide a means to add metadata about your code.

+1


source


Attributes are used to add metadata to .NET (C #) code in a structured manner. However, many people fail to realize that there are actually two types of attributes.

The simplest are custom attributes, in which you define an attribute that certain classes look for in order to change the way they work. A common example is an attribute System.Xml.Serialization

that is read using XmlSerializer

to change its output, eg. a class can be tagged like this to indicate its namespace and that the field should be an attribute:

[XmlType(Namespace = "http://mycompany.com/")]
public class MyClass
{
    [XmlAttribute]
    public string MyField;
}

      



Custom attributes like this have no meaning to the compiler or runtime, they are simply added to the class as part of its metadata and can be retrieved by calling Type.GetCustomAttributes

.

The other main group of attributes are pseudo-custom attributes, which actually make sense to either the compiler or the runtime. EXAMPLE informed Haacked with SerializableAttribute

is actually an example psevdostandartnogo attribute. It is actually stored as part of the type definition and cannot be retrieved with Type.GetCustomAttributes

. You cannot create your own pseudo-standard attributes.

So, probably what you mean here is a custom attribute that a specific tool is looking for.

+1


source







All Articles