Table of Contents

MemberArgumentDecoratorExtensions Class

Definition

Extension methods for the MemberArgument class hidden behind the IDecorator<T> interface.

public static class MemberArgumentDecoratorExtensions
Inheritance
object
MemberArgumentDecoratorExtensions

Examples

The following example demonstrates how to reconstruct an exception from a recorded member argument stack using the MemberArgumentDecoratorExtensions class accessed through the Decorator class.

using System;
using System.Collections.Generic;
using Cuemon;
using Cuemon.Reflection;

namespace MyApp.Examples;

public class MemberArgumentDecoratorExtensionsExample
{
    public Exception ReconstructException()
    {
        // Simulate a recorded stack of member arguments representing an exception chain
        var stack = new Stack<IList<MemberArgument>>();

        var innerArgs = new List<MemberArgument>
        {
            new MemberArgument("type", typeof(InvalidOperationException)),
            new MemberArgument("message", "Inner operation failed.")
        };
        stack.Push(innerArgs);

        var outerArgs = new List<MemberArgument>
        {
            new MemberArgument("type", typeof(ArgumentException)),
            new MemberArgument("message", "Outer argument error."),
            new MemberArgument("paramName", "myParam"),
        };
        stack.Push(outerArgs);

        // Reconstruct the exception chain from the recorded arguments
        return Decorator.Enclose(stack).CreateException();

}
}

Methods

Name Description
CreateException(IDecorator<Stack<IList<MemberArgument>>>, bool)

Converts the underlying Stack<T> of the decorator that has one or more sequences of MemberArgument into an Exception. This API supports the product infrastructure and is not intended to be used directly from your code.

See Also