Table of Contents

Class MemberArgumentDecoratorExtensions

Namespace
Cuemon.Reflection
Assembly
Cuemon.Core.dll

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.

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

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.

public static Exception CreateException(this IDecorator<Stack<IList<MemberArgument>>> decorator, bool parseAsXml = false)

Parameters

decorator IDecorator<Stack<IList<MemberArgument>>>

The IDecorator<T> to extend.

parseAsXml bool

When true, the Message is parsed using \n as newline; otherwise NewLine is used. Reason for this design is explained here: https://www.w3.org/TR/REC-xml/#sec-line-ends

Returns

Exception

An instance of an Exception if the conversion was successful; null otherwise.

Exceptions

ArgumentNullException

decorator cannot be null.

See Also