Table of Contents

Decorator<T> Class

Definition

Namespace
Cuemon
Assemblies
Cuemon.Kernel.dll
Source
src/Cuemon.Kernel/Decorator.cs

Provides a generic way to support hiding of non-common extension methods by enclosing/wrapping an object within the IDecorator<T> interface.

public class Decorator<T> : IDecorator<T>

Type Parameters

T

The type of the inner wrapped object.

Inheritance
Decorator<T>
Implements

Examples

The following example demonstrates how to use Decorator<T> to wrap a value and access it through the decorator pattern.

using System;
using Cuemon;

namespace MyApp.Wrapping;

public class DecoratorOfTExample
{
    public void Demonstrate()
    {
        var numbers = new[] { 10, 20, 30 };
        var decorator = Decorator.Enclose(numbers);

        // Access the wrapped inner value through the Inner property
        int[] inner = decorator.Inner;
        Console.WriteLine(string.Join(", ", inner)); // "10, 20, 30"

        // ArgumentName is set automatically when using EncloseToExpose
        var withArgName = Decorator.EncloseToExpose(numbers);
        Console.WriteLine(withArgName.ArgumentName); // "numbers"

        // Syntactic sugar for type-level decoration
        var syntactic = Decorator.Syntactic<string>();
        Console.WriteLine(syntactic.Inner); // null (default)

}
}

Properties

Name Description
ArgumentName

Gets the name of the argument from which this decorator originates.

Inner

Gets the inner object of this decorator.

See Also