Pygmalions.Prism.Decorating
1.0.2
dotnet add package Pygmalions.Prism.Decorating --version 1.0.2
NuGet\Install-Package Pygmalions.Prism.Decorating -Version 1.0.2
<PackageReference Include="Pygmalions.Prism.Decorating" Version="1.0.2" />
paket add Pygmalions.Prism.Decorating --version 1.0.2
#r "nuget: Pygmalions.Prism.Decorating, 1.0.2"
// Install Pygmalions.Prism.Decorating as a Cake Addin #addin nuget:?package=Pygmalions.Prism.Decorating&version=1.0.2 // Install Pygmalions.Prism.Decorating as a Cake Tool #tool nuget:?package=Pygmalions.Prism.Decorating&version=1.0.2
Prism Decorating
This plugin provides a mechanism to modify the behavior of functions in run-time.
How to Use
By simply mark [Decorate]
attribute on any non-final virtual method of a class,
this plugin will implement the IDecorated
interface in the proxy class.
Method decorators can be get through GetMethodDecorator(MethodInfo)
method provided by IDecorated
interface.
For example, this is the code of a sample class:
public class SampleObject
{
[Decorate]
public virtual int Value { get => BackingValue; set => BackingValue = value; }
public int BackingValue = 0;
[Decorate]
public virtual int Add(int value) => BackingValue + value;
public SampleObject()
{}
public SampleObject(int initialValue)
{
BackingValue = initialValue;
}
}
Firstly, initialize a proxy generator and load this plugin:
// Initialize a proxy generator.
var generator = new Generator();
// Load decoration plugin.
generator.RegisterPlugin(new DecorationPlugin());
Secondly, create a instance of the proxy class:
var instance = Activator.CreateInstance(generator.GetProxy<SampleObject>());
Convert this instance into the original type and the IDecorated
interface separately:
var proxy = (IDecorated)instance!;
var sample = (SampleObject)instance!;
Get the decorator of Add(int)
method.
In this example, the code in that method will be skipped, and the return value will be set to 10.
var decorator =
proxy.GetMethodDecorator(typeof(SampleObject).GetMethod(nameof(SampleObject.Add))!);
decorator!.Invoking += (ref Invocation invocation) =>
{
invocation.Result = 10;
invocation.Skipped = true;
};
Invoke the decorated method, the result
here will be 10,
no matter what the argument is given.
var result = sample.Add(3);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Pygmalions.Prism.Framework (>= 1.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.