Decorator Class
Definition
Provides a way to support hiding of non-common extension methods by enclosing/wrapping an object within the IDecorator<T> interface.
public static class Decorator
- Inheritance
-
Decorator
Examples
The following example demonstrates how to wrap values using Decorator.Enclose and related methods. It shows accessing the inner value, argument name, syntactic default, and raw (nullable) wrapping.
using System;
using Cuemon;
namespace MyApp.Wrapping;
public class DecoratorExample
{
public void Demonstrate()
{
var wrappedString = Decorator.Enclose("Hello, World!");
Console.WriteLine(wrappedString.Inner); // "Hello, World!"
Console.WriteLine(wrappedString.ArgumentName); // ""
var withArg = Decorator.EncloseToExpose("test", argumentName: "myArg");
Console.WriteLine(withArg.ArgumentName); // "myArg"
var syntactic = Decorator.Syntactic<DateTime>();
Console.WriteLine(syntactic.Inner); // "01-01-0001 00:00:00" (default(DateTime))
var raw = Decorator.RawEnclose<string>(null);
Console.WriteLine(raw.Inner is null); // True
}
}
Remarks
The original idea for this class was due to feedback from developers; often they are overwhelmed by vast numbers of extensions methods for various types of various libraries.
To help reduce the cognitive load inferred from this feedback (and to avoid traditional Utility/Helper classes), these interfaces and classes was added, leaving a sub-convenient way (fully backed by IntelliSense) to use non-common extension methods.
Pure extension methods should (IMO) be used in the way Microsoft has a paved path to the many NuGet packages complementing the .NET platform and overall follow these guidelines: https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/extension-methods.
Non-common extension methods could also include those rare cases were you need to support your product infrastructure cross-assembly.
Methods
| Name | Description |
|---|---|
| EncloseToExpose<T>(T, bool, string) | Encloses the specified |
| Enclose<T>(T, bool) | Encloses the specified |
| RawEnclose<T>(T) | Encloses the specified |
| Syntactic<T>() | Syntactic sugar for the rare cases where retrieving properties exposed as methods is a necessity. |