ExceptionDescriptorAttribute Class
Definition
- Namespace
- Cuemon.Diagnostics
- Assemblies
- Cuemon.Core.dll
Provides information about an Exception, in a developer friendly way, optimized for open- and otherwise public application programming interfaces (API).
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class ExceptionDescriptorAttribute : ResourceAttribute
- Inheritance
-
ExceptionDescriptorAttribute
- Inherited Members
Examples
The following example demonstrates how to annotate a method with
using System;
using System.Linq;
using Cuemon.Diagnostics;
namespace MyApp.Examples;
public static class ExceptionDescriptorAttributeExample
{
[ExceptionDescriptor(typeof(ArgumentNullException),
Code = "ERR_NULL_ARGUMENT",
Message = "A required parameter was not provided.",
HelpLink = "https://example.com/errors/null-argument")]
public static void ProcessOrder(string orderId)
{
if (orderId == null) { throw new ArgumentNullException(nameof(orderId)); }
}
public static void Demonstrate()
{
var attribute = (ExceptionDescriptorAttribute)Attribute
.GetCustomAttributes(typeof(ExceptionDescriptorAttributeExample).GetMethod(nameof(ProcessOrder))!, typeof(ExceptionDescriptorAttribute))
.Single();
Console.WriteLine(attribute.FailureType.Name);
Console.WriteLine(attribute.Code);
Console.WriteLine(attribute.Message);
Console.WriteLine(attribute.HelpLink);
}
}
Constructors
| Name | Description |
|---|---|
| ExceptionDescriptorAttribute(Type) | Initializes a new instance of the ExceptionDescriptorAttribute class. |
Properties
| Name | Description |
|---|---|
| Code | Gets or sets an error code that uniquely identifies the type of failure. |
| FailureType | |
| HelpLink | Gets or sets a link to the help page associated with this failure. |
| Message | Gets or sets a default message that describes the current failure. |
| MessageResourceName | Gets or sets the resource name (property name) to use as the key for looking up a localized message string. |