Table of Contents

MemberArgumentDecoratorExtensions Class

Definition

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

public static class MemberArgumentDecoratorExtensions
Inheritance
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.

// Program.cs
using System;
using System.Collections.Generic;
using Cuemon;
using Cuemon.Reflection;
using MyApp.Examples;

Console.WriteLine(new MemberArgumentDecoratorExtensionsExample().ReconstructException());

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 outerArgs = new List<MemberArgument>
            {
                new MemberArgument("type", typeof(ArgumentException)),
                new MemberArgument("message", "Outer argument error."),
                new MemberArgument("paramName", "myParam"),
                new MemberArgument("innerException", null)
            };
            stack.Push(outerArgs);

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

            // 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