Class Decorator<T>
- Namespace
- Cuemon
- Assembly
- Cuemon.Kernel.dll
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
TThe type of the inner wrapped object.
- Inheritance
-
Decorator<T>
- Implements
-
IDecorator<T>
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
ArgumentName
Gets the name of the argument from which this decorator originates.
public string ArgumentName { get; }
Property Value
- string
The name of the argument from which this decorator originates.
Inner
Gets the inner object of this decorator.
public T Inner { get; }
Property Value
- T
The inner object of this decorator.
See Also
IDecorator<T>