AssemblyFacilityIdentifierAttribute Class |
[This is preliminary documentation and is subject to change.]
Namespace: NerdyDuck.CodedExceptions
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] [ComVisibleAttribute(false)] public sealed class AssemblyFacilityIdentifierAttribute : Attribute
The AssemblyFacilityIdentifierAttribute type exposes the following members.
Name | Description | |
---|---|---|
![]() | AssemblyFacilityIdentifierAttribute |
Initializes a new instance of the AssemblyFacilityIdentifierAttribute with the specified facility id.
|
Name | Description | |
---|---|---|
![]() | FacilityId |
Gets the identifier for the facility (= the attributed assembly).
|
![]() | TypeId | When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.) |
Name | Description | |
---|---|---|
![]() | Equals | Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.) |
![]() ![]() | FromAssembly |
Gets an AssemblyFacilityIdentifierAttribute located in the specified assembly.
|
![]() ![]() | FromType |
Gets an AssemblyFacilityIdentifierAttribute located in the assembly that defines the specified type.
|
![]() | GetHashCode | Returns the hash code for this instance. (Inherited from Attribute.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | IsDefaultAttribute | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.) |
![]() | Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
![]() ![]() | _AttributeGetIDsOfNames | Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.) |
![]() ![]() | _AttributeGetTypeInfo | Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.) |
![]() ![]() | _AttributeGetTypeInfoCount | Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.) |
![]() ![]() | _AttributeInvoke | Provides access to properties and methods exposed by an object. (Inherited from Attribute.) |
Apply this attribute to an assembly if that assembly throws exceptions with custom HResult values, and you want to create values that adhere to the HRESULT format specified by Microsoft. See the HRESULT definition at MSDN for more information about the definition of HRESULT values.
The FacilityId value of the attribute defines the lower bits of the higher two bytes of the HRESULT value. It can be used to discover the assembly that an exception is thrown by. The value can range between 0 and 2047, as 11 bits are available for the facility. The highest 5 bits are reserved, and should always be set to value 0xa, as that specifies a custom HRESULT value (values from Microsoft always start with 0x8). The lower two bytes of the HRESULT are used for specific error numbers, so a maximum of 65,535 individual error numbers per assembly are possible using this schema.
First decorate your assembly with the AssemblyFacilityIdentifierAttribute.
using NerdyDuck.CodedExceptions; [assembly: AssemblyFacilityIdentifier(0x0305)]
Then you can use the AssemblyFacilityIdentifierAttribute and HResultHelper classes to retrieve the facility id and build a HRESULT value.
using NerdyDuck.CodedExceptions; using System; using System.Reflection; namespace Example { class Program { static void Main() { int facilityId = AssemblyFacilityIdentifierAttribute.FromAssembly(Assembly.GetExecutingAssembly()).FacilityId; // facilityId is 0x0305 int baseHResult = HResultHelper.GetBaseHResult(facilityId); // baseHResult is 0xa3050000 int myHResult = baseHResult | 0x42; // myHResult is 0xa3050042; } } }