MethodAggregator 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package MethodAggregator --version 1.0.3
                    
NuGet\Install-Package MethodAggregator -Version 1.0.3
                    
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="MethodAggregator" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MethodAggregator" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MethodAggregator" />
                    
Project file
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 MethodAggregator --version 1.0.3
                    
#r "nuget: MethodAggregator, 1.0.3"
                    
#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 MethodAggregator@1.0.3
                    
#: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=MethodAggregator&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=MethodAggregator&version=1.0.3
                    
Install as a Cake Tool

MethodAggregator

MethodAggregator is a C# library that allows you to manage, register, and execute methods dynamically. It provides functionality to find and execute the most suitable method based on the provided parameters and return type.

Usage

How to use the Execute method:

using MethodAggregator;

public class Program
{
    public static void Main(string[] args)
    {
        IMethodAggregator aggregator = new MethodAggregator();
        
        // Register methods
        aggregator.Register((Func<int, int, int>)Add);
        aggregator.Register((Func<double, double, double>)Add);
        
        // Execute methods
        int intResult = aggregator.Execute<int>("Add", 1, 2);
        double doubleResult = aggregator.Execute<double>("Add", 1.0, 2.0);

        // Unregister methods
        aggregator.Unregister((Func<int, int, int>)Add);
        aggregator.Unregister((Func<double, double, double>)Add);
    }

    public static int Add(int a, int b)
    {
        return a + b;
    }

    public static double Add(double a, double b)
    {
        return a + b;
    }
}

How to use the SimpleExecute method:

using MethodAggregator;

public class Program
{
    public static void Main(string[] args)
    {
        IMethodAggregator aggregator = new MethodAggregator();

        // Register methods
        aggregator.Register((int x, int y) => x + y, "Add");
        aggregator.Register((int x, double y) => x * y, "Multiply");

        // Examples for SimpleExecute
        int sumResult = aggregator.SimpleExecute<int>(10, 20); // Invokes the Add method
        int multiplyResult = aggregator.SimpleExecute<int>(10, 5.5); // Invokes the Multiply method

        Console.WriteLine($"Sum: {sumResult}");
        Console.WriteLine($"Multiplication: {multiplyResult}");
    }
}

Methods

The MethodAggregator class provides the following methods for managing and executing registered methods:

  • Execute<T>(string name, params object[] parameters): Executes the method with the specified name and parameters, returning a value of type T
  • Execute(string name, params object[] parameters): Executes the method with the specified name and parameters, without returning a value
  • SimpleExecute<T>(params object[] parameters): Executes the method with the specified parameters, without specifying a name, and returns a value of type T
  • SimpleExecute(params object[] parameters): Executes the method with the specified parameters, without specifying a name or returning a value
  • TryExecute<T>(out T returnValue, string name, params object[] parameters): Attempts to execute the method with the specified name and parameters, returning a value of type T, and returns a boolean indicating whether the operation succeeded
  • TryExecute(string name, params object[] parameters): Attempts to execute the method with the specified name and parameters, without returning a value, and returns a boolean indicating whether the operation succeeded
  • IsRegistered(Delegate del): Returns a boolean indicating whether the specified delegate is registered in the aggregator
  • Register(Delegate del, string name = null): Registers the specified delegate with the given name, or the delegate's method name by default
  • Unregister(Delegate del): Unregisters the specified delegate from the aggregator
  • Dispose(): Releases all resources used by the MethodAggregator instance

Dependencies

JetBrains.Annotations

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 256 9/18/2023
2.0.0 350 5/11/2023
1.0.5 339 5/11/2023
1.0.4 372 5/11/2023 1.0.4 is deprecated because it is no longer maintained.
1.0.4-ci.19 349 5/11/2023 1.0.4-ci.19 is deprecated because it is no longer maintained.
1.0.4-ci.18 359 5/4/2023 1.0.4-ci.18 is deprecated because it is no longer maintained.
1.0.4-ci.17 360 5/4/2023 1.0.4-ci.17 is deprecated because it is no longer maintained.
1.0.4-ci.16 355 5/4/2023 1.0.4-ci.16 is deprecated because it is no longer maintained.
1.0.4-ci.15 363 4/13/2023 1.0.4-ci.15 is deprecated because it is no longer maintained.
1.0.4-ci.14 364 4/9/2023 1.0.4-ci.14 is deprecated because it is no longer maintained.
1.0.4-ci.13 358 4/9/2023 1.0.4-ci.13 is deprecated because it is no longer maintained.
1.0.4-ci.12 358 4/9/2023 1.0.4-ci.12 is deprecated because it is no longer maintained.
1.0.4-ci.11 351 4/9/2023 1.0.4-ci.11 is deprecated because it is no longer maintained.
1.0.4-ci.10 368 4/9/2023 1.0.4-ci.10 is deprecated because it is no longer maintained.
1.0.4-ci.8 356 4/9/2023 1.0.4-ci.8 is deprecated because it is no longer maintained.
1.0.4-ci.7 360 4/9/2023 1.0.4-ci.7 is deprecated because it is no longer maintained.
1.0.4-ci.6 359 4/7/2023 1.0.4-ci.6 is deprecated because it is no longer maintained.
1.0.4-ci.5 371 4/5/2023 1.0.4-ci.5 is deprecated because it is no longer maintained.
1.0.4-ci.4 359 4/4/2023 1.0.4-ci.4 is deprecated because it is no longer maintained.
1.0.3 722 4/4/2023 1.0.3 is deprecated because it is no longer maintained.