Adr.MyProxy
3.0.0
dotnet add package Adr.MyProxy --version 3.0.0
NuGet\Install-Package Adr.MyProxy -Version 3.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Adr.MyProxy" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Adr.MyProxy" Version="3.0.0" />
<PackageReference Include="Adr.MyProxy" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Adr.MyProxy --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Adr.MyProxy, 3.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Adr.MyProxy@3.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Adr.MyProxy&version=3.0.0
#tool nuget:?package=Adr.MyProxy&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MyProxy
MyProxy allow us to add proxy or turn our objects in event listeners objects.
Installation
.NET CLI
dotnet add package Adr.MyProxy --version 3.0.0
Nuget package manager
PM> Install-Package Adr.MyProxy -Version 3.0.0
packageReference
<PackageReference Include="Adr.MyProxy " Version="3.0.0" />
Usage
With this sample classes:
public interface IPerson
{
string Name { get; set; }
void Talk(string msg);
void Run();
int AskAge();
IEnumerable<IPerson> GetParents();
}
public class Person : IPerson
{
public string Name { get; set; }
public int AskAge() => 23;
public IEnumerable<IPerson> GetParents() => new List<IPerson> { new Person(), new Person() };
public void Run() => Console.WriteLine($"{Name}, run !");
public void Talk(string msg) => Console.WriteLine($"{Name} said: \"{msg}\"");
}
We can add event listeners
IPerson p = MyProxy.DynamicExtensions.CreateListener<Person>(); // create a instance with a Person with listeners and cast to interface type to use implemented listeners methods
p.SetPropertyValue(nameof(IPerson.Name), "Adriano"); // set prop with reflection
// add listener
p.When(nameof(p.AskAge), args =>
{
Console.WriteLine("Add 1 to age: 23 => 24");
return ((int)args.Result!) + 1;
});
int age = p.AskAge(); // returns 24
// add listener
p.When(nameof(p.GetParents), args =>
{
Console.WriteLine("Add name to parents");
List<IPerson>? parents = args.Result as List<IPerson>;
if (parents != null && parents.Count == 2)
{
parents[0].SetPropertyValue(nameof(IPerson.Name), "Father");
parents[1].SetPropertyValue(nameof(IPerson.Name), "Mother");
}
else return null!;
return parents!;
});
var parets = p.GetParents(); // returns Person.Name = Father, Person.Name = Mother
// add listener
p.When(nameof(p.AskAge), args =>
{
Console.WriteLine($"{args.Sender!.GetPropertyValue(nameof(p.Name))} run from proxy!");
return null!;
});
p.Run(); // write on console "Adriano run from proxy!"
We can add before and after delegates to all methods in a object:
IPerson p = new Person()
.AddProxy<Person, IPerson>(
new BeforeMethodCall(args => Console.WriteLine($"Berofe the method {args.Method!.Name}")),
new AfterMethodCall(args => {
Console.WriteLine($"After the method, we also can change the result");
return args.Result;
}),
new ReplaceMethodCall(args => {
Console.WriteLine($"We can replace the method {args.Method!.Name} too");
return args.Method!.ReturnType.Equals(typeof(void)) ? null! : Activator.CreateInstance(args.Method.ReturnType)!;
}),
new object[]{});;
p.Name = "Adriano";
p.Run();
Console.Read();
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
- Adr.MyRefs (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
3.0.0