System.Reflection.DispatchProxy 4.8.0

About

Provides a DispatchProxy class to dynamically create proxy instances that implement a specified interface.

Key Features

Method invocations on a generated proxy instance are dispatched to a Invoke() method. Having a single invoke method allows centralized handling for scenarios such as logging, error handling and caching.

How to Use

Create the proxy class that derives from DispatchProxy, override Invoke() and call one of the static DispatchProxy.Create() methods to generate the proxy type.

The example below intercepts calls to the ICallMe interface and logs them.

class Program
{
    static void Main(string[] args)
    {
        ICallMe proxy = LoggingDispatchProxy.Create<ICallMe>(new MyClass());
        proxy.CallMe("Hello!");
    }
}

public interface ICallMe
{
    void CallMe(string name);
}

public class MyClass : ICallMe
{
    public void CallMe(string message)
    {
        Console.WriteLine($"Inside the called method with input '{message}'");
    }
}

public class LoggingDispatchProxy : DispatchProxy
{
    private ICallMe _target;

    protected override object Invoke(MethodInfo targetMethod, object[] args)
    {
        Console.WriteLine($"Calling method: '{targetMethod.Name}' with arguments: '{string.Join(", ", args)}'");
        object result = targetMethod.Invoke(_target, args);
        Console.WriteLine($"Called method: '{targetMethod.Name}'.");
        return result;
    }

    public static T Create<T>(T target) where T : class
    {
        LoggingDispatchProxy proxy = DispatchProxy.Create<T, LoggingDispatchProxy>() as LoggingDispatchProxy;
        proxy._target = (ICallMe)target;
        return proxy as T;
    }
}

Main Types

The main types provided by this library are:

  • System.Reflection.DispatchProxy

Additional Documentation

License

System.Reflection.DispatchProxy is released as open source under the MIT license.

Showing the top 20 packages that depend on System.Reflection.DispatchProxy.

Packages Downloads
Microsoft.NETCore
Provides a set of packages that can be used when building portable libraries on .NETCore based platforms.
89
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. 124038c13eafa08e4bd8c2bfd04bb0633f958bc8 When using NuGet 3.x this package requires at least version 3.4.
87
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. 1a165a1588309bd8c34f77e1f926e6dbf6ae30d0 When using NuGet 3.x this package requires at least version 3.4.
105
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. 811c3ce6c01229f0eaead96f3eb10112a9066b34 When using NuGet 3.x this package requires at least version 3.4.
89
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. b61e1596d6afb8168ebd9a46d560af4413c6d57f When using NuGet 3.x this package requires at least version 3.4.
100
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. d6a56162401485f1c898ce7e78f95641954997b3 When using NuGet 3.x this package requires at least version 3.4.
88
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. eb9bc9205169e4c00d218d03167a564a7429921f When using NuGet 3.x this package requires at least version 3.4.
90
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. When using NuGet 3.x this package requires at least version 3.4.
89
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. When using NuGet 3.x this package requires at least version 3.4.
94
Microsoft.NETCore.App
A set of .NET API's that are included in the default .NET Core application model. When using NuGet 3.x this package requires at least version 3.4.
96
System.Private.ServiceModel
Internal implementation package not meant for direct consumption. Please do not reference directly. Provides implementation of System.ServiceModel packages. 133512ecc8d49b69010bdc737a2c85e9401842d2 When using NuGet 3.x this package requires at least version 3.4.
94
System.Private.ServiceModel
Internal implementation package not meant for direct consumption. Please do not reference directly. Provides implementation of System.ServiceModel packages. 32c5f3642810d5731e67683ba415757fa7ad1a6c When using NuGet 3.x this package requires at least version 3.4.
95
System.Private.ServiceModel
Internal implementation package not meant for direct consumption. Please do not reference directly. Provides implementation of System.ServiceModel packages. 8ee6d65a6da34d4d37ce1d00d87febfeed0561a9 When using NuGet 3.x this package requires at least version 3.4.
108
System.Private.ServiceModel
Internal implementation package not meant for direct consumption. Please do not reference directly. Provides implementation of System.ServiceModel packages. ef12c524d29edfd2f5db96cf1ac60b2372986790 When using NuGet 3.x this package requires at least version 3.4.
116
System.Private.ServiceModel
Package Description
91
System.Private.ServiceModel
Package Description
94
System.Private.ServiceModel
Package Description
96
System.Private.ServiceModel
Package Description
103
System.Private.ServiceModel
Package Description
110
System.Private.ServiceModel
Package Description
112

.NET Framework 4.6.2

  • No dependencies.

.NET Core 3.1

  • No dependencies.

.NET Standard 2.0

.NET Standard 2.1

  • No dependencies.

Version Downloads Last updated
5.0.0-preview.7.20364.11 67 08/19/2022
5.0.0-preview.6.20305.6 59 09/22/2022
5.0.0-preview.5.20278.1 59 09/22/2022
5.0.0-preview.4.20251.6 94 09/24/2022
5.0.0-preview.3.20214.6 34 09/24/2022
5.0.0-preview.2.20160.6 65 09/21/2022
5.0.0-preview.1.20120.5 46 09/24/2022
4.8.0 9 11/24/2024
4.7.1 23 09/22/2022
4.7.0 107 09/24/2022
4.7.0-preview3.19551.4 58 09/21/2022
4.7.0-preview2.19523.17 69 09/25/2022
4.7.0-preview1.19504.10 34 09/23/2022
4.6.0 53 09/24/2022
4.6.0-rc1.19456.4 40 09/23/2022
4.6.0-preview9.19421.4 46 09/26/2022
4.6.0-preview9.19416.11 109 09/24/2022
4.6.0-preview8.19405.3 79 09/23/2022
4.6.0-preview7.19362.9 69 09/22/2022
4.6.0-preview6.19303.8 41 09/26/2022
4.6.0-preview6.19264.9 105 09/22/2022
4.6.0-preview5.19224.8 102 09/24/2022
4.6.0-preview4.19212.13 46 09/22/2022
4.6.0-preview3.19128.7 77 09/22/2022
4.6.0-preview.19073.11 60 09/21/2022
4.6.0-preview.18571.3 87 09/22/2022
4.5.1 55 09/22/2022
4.5.0 54 10/15/2022
4.5.0-rc1 114 09/22/2022
4.5.0-preview2-26406-04 33 09/23/2022
4.5.0-preview1-26216-02 82 09/21/2022
4.4.0 94 09/24/2022
4.4.0-preview2-25405-01 55 09/22/2022
4.4.0-preview1-25305-02 83 09/26/2022
4.3.0 39 09/21/2022
4.3.0-preview1-24530-04 72 09/22/2022
4.0.1 37 09/23/2022
4.0.1-rc2-24027 38 09/23/2022
4.0.1-beta-23516 43 09/24/2022
4.0.1-beta-23409 42 09/23/2022
4.0.1-beta-23225 24 09/21/2022
4.0.0 84 09/22/2022
4.0.0-beta-23109 45 09/22/2022
4.0.0-beta-23019 90 09/21/2022
4.0.0-beta-22816 116 09/24/2022