System.Reflection.DispatchProxy 4.8.0

Prefix Reserved
dotnet add package System.Reflection.DispatchProxy --version 4.8.0                
NuGet\Install-Package System.Reflection.DispatchProxy -Version 4.8.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="System.Reflection.DispatchProxy" Version="4.8.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add System.Reflection.DispatchProxy --version 4.8.0                
#r "nuget: System.Reflection.DispatchProxy, 4.8.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.
// Install System.Reflection.DispatchProxy as a Cake Addin
#addin nuget:?package=System.Reflection.DispatchProxy&version=4.8.0

// Install System.Reflection.DispatchProxy as a Cake Tool
#tool nuget:?package=System.Reflection.DispatchProxy&version=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.

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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  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.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETStandard 2.0

  • .NETStandard 2.1

    • No dependencies.

NuGet packages (149)

Showing the top 5 NuGet packages that depend on System.Reflection.DispatchProxy:

Package Downloads
System.Private.ServiceModel

Package Description

CoreWCF.Primitives

CoreWCF is a port of the service side of Windows Communication Foundation (WCF) to .NET Core. The goal of this project is to enable existing WCF services to move to .NET Core.

Microsoft.NETCore

Provides a set of packages that can be used when building portable libraries on .NETCore based platforms. \r\n TFS ID: 1599443, GitHub SHA: https://github.com/dotnet/corefx/tree/eede273a4dfabcea608621f5e1bbf8ad00584cfb

Lykke.HttpClientGenerator

This package helps to generate client proxy for an api using the Refit library. It adds cache and retries using Polly to the generated proxies. User logic can also be added as wrappers to the requests or to the method calls.

Z.EntityFramework.Classic

Entity Framework Classic is an EF6 fork with performance enhancement, new features, and .NET Core support. This package is FREE (Community Version) Some features are Prime (Enterprise Version) Prime features can be disabled with "EntityFrameworkManager.IsCommunity = true;"

GitHub repositories (11)

Showing the top 5 popular GitHub repositories that depend on System.Reflection.DispatchProxy:

Repository Stars
dotnet/wcf
This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
CoreWCF/CoreWCF
Main repository for the Core WCF project
malware-dev/MDK-SE
Malware's Development Kit for SE
RRQM/TouchSocket
TouchSocket is an integrated .NET networking framework that includes modules for socket, TCP, UDP, SSL, named pipes, HTTP, WebSocket, RPC, and more. It offers a one-stop solution for TCP packet issues and enables quick implementation of custom data message parsing using protocol templates.
open-telemetry/opentelemetry-dotnet-contrib
This repository contains set of components extending functionality of the OpenTelemetry .NET SDK. Instrumentation libraries, exporters, and other components can find their home here.
Version Downloads Last updated
4.8.0 3,560 11/12/2024
4.7.1 120,710,842 5/12/2020
4.7.0 1,220,832 12/3/2019
4.7.0-preview3.19551.4 679 11/13/2019
4.7.0-preview2.19523.17 674 11/1/2019
4.7.0-preview1.19504.10 676 10/15/2019
4.6.0 759,673 9/23/2019
4.6.0-rc1.19456.4 715 9/16/2019
4.6.0-preview9.19421.4 806 9/4/2019
4.6.0-preview9.19416.11 646 9/4/2019
4.6.0-preview8.19405.3 813 8/13/2019
4.6.0-preview7.19362.9 725 7/23/2019
4.6.0-preview6.19303.8 2,633 6/12/2019
4.6.0-preview6.19264.9 693 9/4/2019
4.6.0-preview5.19224.8 955 5/6/2019
4.6.0-preview4.19212.13 763 4/18/2019
4.6.0-preview3.19128.7 797 3/6/2019
4.6.0-preview.19073.11 871 1/29/2019
4.6.0-preview.18571.3 929 12/3/2018
4.5.1 4,444,030 6/18/2018
4.5.0 147,480,943 5/29/2018
4.5.0-rc1 4,247,200 5/6/2018
4.5.0-preview2-26406-04 228,939 4/10/2018
4.5.0-preview1-26216-02 44,218 2/26/2018
4.4.0 53,005,152 8/11/2017
4.4.0-preview2-25405-01 17,694 6/27/2017
4.4.0-preview1-25305-02 97,892 5/9/2017
4.3.0 39,104,596 11/15/2016
4.3.0-preview1-24530-04 52,192 10/24/2016
4.0.1 89,926,021 6/27/2016
4.0.1-rc2-24027 2,102,528 5/16/2016
4.0.1-beta-23516 22,534 11/18/2015
4.0.1-beta-23409 4,603 10/15/2015
4.0.1-beta-23225 136,750 9/2/2015
4.0.0 1,515,656 7/29/2015
4.0.0-beta-23109 3,676 7/27/2015
4.0.0-beta-23019 3,776 6/30/2015
4.0.0-beta-22816 3,773 4/24/2015