Attribute Scopes

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language topic
Feel free to add your notes to this topic below.



By default, attributes found in code will be applied to the next code element following them - for example attributes might be placed in front of a type declaration, a method or a parameter.

In addition, the Delphi Prism compiler provides the following 3 scope prefixes that can be used to attach attributes to places that don't have a representation in code, such as the assembly itself:

Assembly Attributes

You may need to define attributes that apply at the assembly level and control information or behavior for the entire assembly (such as COM visibility, strong name or the assembly's title). The assembly prefix can be used to attach an attribute to the assembly:

[assembly:AssemblyTitle('test')]

Module Attributes

In theory, an assembly in .NET is a collection of one or more modules. For Delphi Prism, as for most other .NET languages including C#, there is a one-to-one mapping between assembly and module, but some .NET compilers support multiple modules per assembly.

Still, module attribute scope is supported, because some system attributes are defined to only be applicable at the module level. For example:

[module: Debuggable(True, true)]

Global Attributes

Finally, the global scope allows you to apply attributes to the Global Class that contains global methods and variables defined in your project (if globals are enabled in your project settings).

[global: MyAttribute]

Read/Write Attributes

The read: and write: scopes can be used when the attributes are defined just before a property, to apply attributes on the getter and setter of a property.

Var scope

The var: prefix can be used to attach attributes to the auto generated field. This works for both properties and events.


See Also


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox