Special Attributes

From The Oxygene Language Wiki

Jump to:navigation, search

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



In addition to normal Custom Attributes, the Delphi Prism compiler provides support for the following attribute classes, resulting in specific code or data generated in the output assembly:

Attributes
Description
AssemblyKeyFileAttribute

AssemblyKeyNameAttribute
AssemblyDelaySignAttribute

These attributes control strong-naming and signing of the assembly, as required for installation in the Global Assembly Cache (GAC).

AssemblyVersionAttribute
AssemblyFileVersionAttribute
These two attributes specify the version numbering of the output assembly.

If AssemblyFileVersionAttribute is not specified, the AssemblyVersionAttribute value is used for both the string name and the Win32 file version. If it is specified, the AssemblyFileVersion will be for the Win32 version resource and the AssemblyVersion will go into the strong name.

AssemblyCompanyAttribute
AssemblyProductAttribute
AssemblyCopyrightAttribute

AssemblyTrademarkAttribute
AssemblyCultureAttribute
AssemblyDescriptionAttribute

These attributes contribute additional fields to the assembly strong name and or version information.

OutAttribute Used to mark out params. The .NET runtime passes out parameters by passing them as "by reference" ( var) and setting the out modifier on the parameter.
ComImportAttribute
InAttribute
OptionalAttribute
MarshalAsAttribute
NonSerializableAttribute

SerializableAttribute

These are not real custom attributes, but represent flags in the IL. Delphi Prism knows about these and correctly maps them to the underlying flags.
DllImportAttribute DllImport is used to import functions from unmanaged dlls (such as Win32 dlls or shared objects under Linux/Mono). A static method header can be defined in a class, and the DllImport attribute can be added to specify what dll and what function to import (and possibly more details of how to marshal parameters back and forth) and calls to this method will be directed to the external Win32 dll. See DllImportAttribute for more information.
ConditionalAttribute This attribute is used to mark types or members for conditional compilation.

The compiler will link calls to members with this attribute only if the matching define is set. For example, most methods in RemObjects.DebugServer.dll have the [Conditional('DebugServer')] attribute. This means that if you write code referencing this assembly and use those methods, the actual calls will only be generated if the "DebugServer" define is set for the project or via $IFDEF.

The nice thing about ConditionalAttribute is that it not only works within the same assembly as traditional IFDEFs, but also across assembly boundaries. The DebugServer assembly, for example, is written in C# and completely outside of the control of the Delphi Prism compiler - yet the Delphi Prism-written code will behave differently depending on what defines with which it will be compiled.

ObsoleteAttribute This attribute marks types or members (or entire assemblies) as obsolete. When the compiler notices that you are using an item marked with this attribute, it will generate the appropriate warning or error (depending on the parameters supplied to the attribute).
StructLayout See Records for modifying record storage layouts.
GuidAttribute The compiler will enforce proper GUID format for string constants used with the GuidAttribute.
DebuggableAttribute The compiler will emit this assembly level attribute automatically when compiling, however when it's present, the compiler will use the one defined in code.
MethodImplAttributes An attribute that changes the flags of a MethodDef in the metadata. Used for ComImport and internal calls. Generally these shouldn't be used as they might create invalid code, depending on the combination of flags.
Security Attributes

Delphi Prism provides full support for understanding security attributes and generating the appropriate XML structures inside the output assembly.

CoClassAttribute

This attribute is used in COM imports to define what class is a co-class for the interface this is applied to. When it's defined, the new operator works on interfaces and it will instantiate the proper co-class.

CLSCompliantAttribute

This attribute is used to define whether a type or member is compliant with the Common Language Specification (CLS).

NativeExportAttribute

This is a special attribute that can be used to export a class method as an unmanaged dll export entry.


See Also


Oxygene-48.png

Area: Oxygene Platforms

Platform GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox