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

后端 未结 6 916
走了就别回头了
走了就别回头了 2020-12-15 06:16

Saw some code snippet inside AssemblyInfo.cs like

[assembly: someattributename]

What does this code mean?

I even saw some method to

相关标签:
6条回答
  • 2020-12-15 06:38

    Those are assembly attributes, as explained here.

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

    0 讨论(0)
  • 2020-12-15 06:44

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

    0 讨论(0)
  • 2020-12-15 06:47

    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.

    0 讨论(0)
  • 2020-12-15 06:58

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

    a simple explanation is shown in this Link

    0 讨论(0)
  • 2020-12-15 07:00

    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.

    0 讨论(0)
  • 2020-12-15 07:01

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

    0 讨论(0)
提交回复
热议问题