Class ExceptionDescriptorAttribute
- Namespace
- Cuemon.Diagnostics
- Assembly
- 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
ExceptionDescriptorAttribute(Type)
Initializes a new instance of the ExceptionDescriptorAttribute class.
public ExceptionDescriptorAttribute(Type failureType)
Parameters
Properties
Code
Gets or sets an error code that uniquely identifies the type of failure.
public string Code { get; set; }
Property Value
- string
The number that identifies the type of failure.
FailureType
public Type FailureType { get; }
Property Value
HelpLink
Gets or sets a link to the help page associated with this failure.
public string HelpLink { get; set; }
Property Value
- string
The location of an optional help page associated with this failure.
Message
Gets or sets a default message that describes the current failure.
public string Message { get; set; }
Property Value
- string
The default message that explains the reason for the failure.
MessageResourceName
Gets or sets the resource name (property name) to use as the key for looking up a localized message string.
public string MessageResourceName { get; set; }
Property Value
- string
The resource name (property name) to use as the key for looking up a localized message string that describes the current failure.