System.Reflection.DispatchProxy 4.8.0 (original) (raw)

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:

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. 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 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.

NuGet packages (168)

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

Package Downloads
System.Private.ServiceModel Package Description 509.8M
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. 10.7M
CoreWCF.Http 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. 9.2M
CoreWCF.NetTcp 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. 5.1M
CoreWCF.WebHttp 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. 3.9M

GitHub repositories (12)

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

Repository Stars
CoreWCF/CoreWCF Main repository for the Core WCF project 1.8K
dotnet/wcf This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services. 1.8K
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. 1.3K
malware-dev/MDK-SE Malware's Development Kit for SE 1.0K
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. 641
Code-Sharp/WampSharp A C# implementation of WAMP (The Web Application Messaging Protocol) 388
DevrexLabs/memstate In-memory event-sourced ACID-transactional distributed object graph engine for .NET Standard 376
jacqueskang/IpcServiceFramework .NET Core Inter-process communication framework 371
hikalkan/scs TCP Server/Client Communication and RMI Framework 231
beetlex-io/BeetleX-Samples BeetleX micro services framework (tcp webapi websocket and xrpc) samples 113
zzzprojects/EntityFramework-Classic Entity Framework Classic is a supported version of the latest EF6 codebase. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features. 102
Ginger-Automation/Ginger Ginger Automation IDE 101

Include prerelease

Include vulnerable

Include deprecated

Version Downloads Last Updated
4.8.2 1,665,967 3/19/2025
4.8.0 469,705 11/12/2024
4.7.1 212,573,754 5/12/2020
4.7.0 1,305,519 12/3/2019
4.7.0-preview3.19551.4 1,175 11/13/2019
4.7.0-preview2.19523.17 1,152 11/1/2019
4.7.0-preview1.19504.10 1,169 10/15/2019
4.6.0 817,618 9/23/2019
4.6.0-rc1.19456.4 1,217 9/16/2019
4.6.0-preview9.19421.4 1,299 9/4/2019
4.6.0-preview9.19416.11 1,125 9/4/2019
4.6.0-preview6.19264.9 1,159 9/4/2019