PostSharpAPI ReferencePost­Sharp.​ReflectionDeclaration­Identifier
Open sandboxFocus

DeclarationIdentifier Class

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.

Inheritance
DeclarationIdentifier
Namespace: PostSharp.Reflection
Assembly: PostSharp.dll
Syntax
public sealed class DeclarationIdentifier : ValueType
Remarks

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 guaranteed 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

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.

Constructors

Name Description
DeclarationIdentifier(Int64)

Fields

Name Description
MaxMemberIndex

Maximum number of the same kind in the same type supported by the DeclarationIdentifier class.

MaxTypeIndex

Maximum number of types per assembly supported by the DeclarationIdentifier class.

Properties

Name Description
AssemblyId

Gets a 29-bit of the name of the assembly containing the declaration represented by the current DeclarationIdentifier.

IsNull

Determines whether the current DeclarationIdentifier is null.

MemberIndex

Gets a number that uniquely identifies the member inside its declaring type, for the given member kind.

Null

Gets a null instance of the DeclarationIdentifier type/

TypeIndex

Gets a number that uniquely identifies the type inside its declaring assembly.

Methods

Name Description
Equals(DeclarationIdentifier)
Equals(Object)
GetDeclarationIdentifier(MemberInfo)

Gets the DeclarationIdentifier for a given declaration.

GetDeclaringTypeIdentifier()

Gets the DeclarationIdentifier that represents the declaring type of the declaration represented by the current DeclarationIdentifier.

GetHashCode()

Operators

Name Description
Equality(DeclarationIdentifier, DeclarationIdentifier)

Determines whether two instances of the DeclarationIdentifier type are equal.

Inequality(DeclarationIdentifier, DeclarationIdentifier)

Determines whether two instances of the DeclarationIdentifier type are different.