user705414
user705414

Reputation: 21200

What does the assembly keyword mean in the AssemblyInfo.cs. Does it permit to use method inside?

Saw some code snippet inside AssemblyInfo.cs like

[assembly: someattributename]

What does this code mean?

I even saw some method to be used inside assembly, like

[assembly: log4net.Config.XmlConfigurator(Watch=true)]

Is this the attribute anymore?

Upvotes: 20

Views: 7887

Answers (6)

John Saunders
John Saunders

Reputation: 161783

assembly: is what's known as an attribute target. It specifies that the attribute applies to the assembly itself, and not to any of the types within the assembly. Some other attribute targets are module, return and param.

See "Attributes (C# and Visual Basic)".

Upvotes: 9

luviktor
luviktor

Reputation: 2270

To the second (edited) part of your answer:

No, it is not a method call. log4net.Config.XmlConfigurator is also an attribute defined by log4net. (See the documentation for log4net details.) Its exact declaration is

public class XmlConfiguratorAttribute : ConfiguratorAttribute

What is a little bit misleading in this case is the attribute naming convention. That means when you use an attribute (even on assembly level) you can leave the Attribute suffix from the attribute class name.

Upvotes: 1

Christian.K
Christian.K

Reputation: 49260

Attributes are always applied to an element (e.g. a method, property). The "assembly:" prefix means that the attribute (the part you omitted using '*') is applied to the assembly.

Applying Attributes at the Assembly Level If you want to apply an attribute at the assembly level, use the Assembly keyword. The following code shows the AssemblyNameAttribute applied at the assembly level.

using System.Reflection;
[assembly:AssemblyTitle("My Assembly")]

When this attribute is applied, the string "MyAssembly" is placed in the assembly manifest in the metadata portion of the file. You can view the attribute either by using the MSIL Disassembler (Ildasm.exe) or by creating a custom program to retrieve the attribute.

Upvotes: 19

SShebly
SShebly

Reputation: 2073

General Information about this assembly is controlled through this set of attributes.

a simple explanation is shown in this Link

Upvotes: 2

CodeCaster
CodeCaster

Reputation: 151604

Those are assembly attributes, as explained here.

They make up the version information for your assembly (or: executable) for example.

Upvotes: 3

Rup
Rup

Reputation: 34408

It means this an attribute on the assembly itself and not on a specific class, method, property etc.

Upvotes: 8

Related Questions