This is the online documentation for PostSharp 5.0.
Download PDF or CHM. Go to v4.3 or v5.0

DeclarationIdentifier Structure

Encapsulates a unique identifier of a declaration. The identifier does not contain the kind of declaration. Different declarations of different kinds can have the same identifier.

Namespace:  PostSharp.Reflection
Assembly:  PostSharp (in PostSharp.dll) Version: (
public struct DeclarationIdentifier : IEquatable<DeclarationIdentifier>

The DeclarationIdentifier type exposes the following members.

Public propertyAssemblyId
Gets a 29-bit of the name of the assembly containing the declaration represented by the current DeclarationIdentifier.
Public propertyIsNull
Determines whether the current DeclarationIdentifier is null.
Public propertyMemberIndex
Gets a number that uniquely identifies the member inside its declaring type, for the given member kind.
Public propertyStatic memberNull
Gets a null instance of the DeclarationIdentifier type/
Public propertyTypeIndex
Gets a number that uniquely identifies the type inside its declaring assembly.
Public methodEquals(Object) (Overrides ValueType.Equals(Object).)
Public methodEquals(DeclarationIdentifier)
Public methodStatic memberGetDeclarationIdentifier
Gets the DeclarationIdentifier for a given declaration.
Public methodGetDeclaringTypeIdentifier
Gets the DeclarationIdentifier that represents the declaring type of the declaration represented by the current DeclarationIdentifier.
Public methodGetHashCode (Overrides ValueType.GetHashCode().)
Public operatorStatic memberEquality
Determines whether two instances of the DeclarationIdentifier type are equal.
Public operatorStatic memberInequality
Determines whether two instances of the DeclarationIdentifier type are different.
Public fieldStatic memberMaxMemberIndex
Maximum number of the same kind in the same type supported by the DeclarationIdentifier class.
Public fieldStatic memberMaxTypeIndex
Maximum number of types per assembly supported by the DeclarationIdentifier class.
Extension Methods
Public Extension MethodQueryInterface<T>
Gets the implementation of a specified interface for the specified object.
(Defined by QueryInterfaceExtensions.)

The DeclarationIdentifier concept provides an efficient mechanism to correlate data that depend on the target declaration of the advice. Typically, such data can be computed at build time and serialized into the aspect, then consumed at run time. Without the DeclarationIdentifier concept, the data would be stored in a dictionary, for instance Dictionary<MethodInfo,MethodData> where MethodData is a custom class. However, relying on a dictionary has some performance costs. Thanks to the the DeclarationIdentifier concept, data can be stored in an array, because the MemberIndex is guarantees to be unique in a given type for a given kind of member (for instance, MemberIndex is unique for all methods in the same type). Array lookups are much faster than dictionary lookups and do not rely on reflection, which gives a significant performance benefit.

Note Note

Although the CIL specification allows for up to 2^24 types in the same assembly and 2^24 methods (or other members) in the same type, the DeclarationIdentifier implementation assumes that there will be no more than 2^16 types in the same assembly and 2^16 members of the same kind in the same type. The AssemblyId property to be coded on 32 bits. The AssemblyId is computed by running the MD5 algorithm on the full assembly name. The probability of hash collision is approximately 10^-6 for an application of 100 assemblies and 10^-5 for an application of 1,000 assemblies. Collisions can be avoided by adding the AssemblyIdAttribute custom attribute to one of the assemblies causing a hash collision. Note that hash collisions are not automatically detected by PostSharp. However, you can build a hash collision detection program by looking at the AssemblyIdAttribute custom attribute on all assemblies of your application after PostSharp has been executed.

See Also