Understanding structures in the Assemblyinfo.Cs file

Asked

Viewed 441 times

1

Taking a look at the file AssemblyInfo.cs of a C# project I came across some structures of which I am not recognizing. These are the lines:

[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription ( "" )]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany ( "" )]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright ©  2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

In other languages that I have experience I would say are dicionários. But in C# dicionários are not like that. What kind of structures are these? Some kind of list?

  • The comments generated along with the code says they are attributes. But we are talking about the same attribute resource (decorators python, annotations java)?

1 answer

2


In fact they are called attributes. They are basically annotations that can be used in several contexts. In this case it is created metadata to inform and configure how the Assembly will behave.

It has nothing to do with dictionaries, unless some language uses a non-standard terminology than everyone else uses.

More about the attributes can be read at another question.

You can even create a custom attribute.

In the case posted only the AssemblyCulture is of more than informative use.

  • But doesn’t an attribute always have to be accompanying a method or class since they aim to modify them? Attributes alone in the code, without "decorating" a class or method are valid?

  • 1

    No, like I said, it could be in many contexts. And attributes don’t change anything, they’re just information that can be used for something somewhere. Nor would it make sense to have limitations to use in so few places. The details about the use are in links that I pointed out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.