Click or drag to resize

AssemblyFacilityIdentifierAttribute Class

[This is preliminary documentation and is subject to change.]

When applied to an assembly, specifies the facility id of the assembly when creating HResult values for coded exceptions.
Inheritance Hierarchy
SystemObject
  SystemAttribute
    NerdyDuck.CodedExceptionsAssemblyFacilityIdentifierAttribute

Namespace:  NerdyDuck.CodedExceptions
Assembly:  NerdyDuck.CodedExceptions (in NerdyDuck.CodedExceptions.dll) Version: 2.0.0+2040dad
Syntax
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false, 
	Inherited = false)]
[ComVisibleAttribute(false)]
public sealed class AssemblyFacilityIdentifierAttribute : Attribute
View Source

The AssemblyFacilityIdentifierAttribute type exposes the following members.

Constructors
  NameDescription
Public methodAssemblyFacilityIdentifierAttribute
Initializes a new instance of the AssemblyFacilityIdentifierAttribute with the specified facility id.
Top
Properties
  NameDescription
Public propertyFacilityId
Gets the identifier for the facility (= the attributed assembly).
Public propertyTypeId
When implemented in a derived class, gets a unique identifier for this Attribute.
(Inherited from Attribute.)
Top
Methods
  NameDescription
Public methodEquals
Returns a value that indicates whether this instance is equal to a specified object.
(Inherited from Attribute.)
Public methodStatic memberFromAssembly
Gets an AssemblyFacilityIdentifierAttribute located in the specified assembly.
Public methodStatic memberFromType
Gets an AssemblyFacilityIdentifierAttribute located in the assembly that defines the specified type.
Public methodGetHashCode
Returns the hash code for this instance.
(Inherited from Attribute.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsDefaultAttribute
When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.
(Inherited from Attribute.)
Public methodMatch
When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.
(Inherited from Attribute.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate method_AttributeGetIDsOfNames
Maps a set of names to a corresponding set of dispatch identifiers.
(Inherited from Attribute.)
Explicit interface implementationPrivate method_AttributeGetTypeInfo
Retrieves the type information for an object, which can be used to get the type information for an interface.
(Inherited from Attribute.)
Explicit interface implementationPrivate method_AttributeGetTypeInfoCount
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
(Inherited from Attribute.)
Explicit interface implementationPrivate method_AttributeInvoke
Provides access to properties and methods exposed by an object.
(Inherited from Attribute.)
Top
Remarks

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.

Examples

First decorate your assembly with the AssemblyFacilityIdentifierAttribute.

Assembly.cs
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.

Program.cs
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;
        }
    }
}
See Also