Skip to main content

DudNet by jwshyns

NuGet / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: DudNet

Proxy-pattern source generator

Author: jwshyns

NuGet: https://www.nuget.org/packages/Jwshyns.DudNet/

You can find more details at https://github.com/jwshyns/DudNet

Source: https://github.com/jwshyns/DudNet

Original Readme

note

DudNet NuGet Badge

DudNet is a C# source generator for implementing a proxy pattern.

Example

Generating a proxy for a class is as simple as marking it with the ProxyServiceAttribute as follows:

using DudNet.Attributes;

public interface IExampleService {

public void ExampleFunction();

public int ExampleFunctionWithArgumentAndReturn(int number);

}

[ProxyService]
public class ExampleService : IExampleService {

public void ExampleFunction(){
// omitted for brevity
}

public int ExampleFunctionWithArgumentAndReturn(int number){
// omitted for brevity
}

public void FunctionNotOnInterface(){
// ommitted for brevity
}

}

Which would generate the following two classes:

using System.Runtime.CompilerServices;
using DudNet.Attributes;

public partial class ExampleServiceProxy : IExampleService {

private readonly IExampleService _service;

public void ExampleFunction() {
Interceptor();
ExampleFunctionInterceptor();
_service.ExampleFunction();
}

public int ExampleFunctionWithArgumentAndReturn(int number) {
Interceptor();
ExampleFunctionWithArgumentAndReturnInterceptor(number);
_service.ExampleFunctionWithArgumentAndReturn(number);
}

partial void Interceptor([CallerMemberName]string callerName = null);

partial void ExampleFunctionInterceptor();

partial void ExampleFunctionWithArgumentAndReturnInterceptor(int number);
}

and

using DudNet.Attributes;

public class ExampleServiceDud : IExampleService {

public void ExampleFunction() {
}

public int ExampleFunctionWithArgumentAndReturn(int number) {
}

}

These generated classes can be used by further implementing the partial proxy class as follows:

public partial class ExampleServiceProxy : IExampleService {

public ExampleServiceProxy(ExampleProxyService service) {
// Some logic to determine whether you want to effectively "disable" the service
if (Random.Shared.NextDouble() > 0.5)
{
_service = service;
return;
}

_service = new ExampleServiceDud();
}

partial void Interceptor([CallerMemberName]string callerName = null) {
Console.Writeline("'{caller}' was called", callerName);
}

partial void ExampleFunctionWithArgumentAndReturnInterceptor(int number) {
if(number > 5)
{
throw new Exception("Received number value '{number}' - too high!", number);
}
}

}

About

note

Generate proxy classes for the principal classes

How to use

Example (source csproj, source files)

This is the CSharp Project that references DudNet

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jwshyns.DudNet" Version="1.2.0" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

using System.Runtime.CompilerServices;
using DudNet.Attributes;
using System.Runtime.CompilerServices;

namespace DudNetDemo;

/// <inheritdoc cref="IPerson"/>
public partial class PersonDud : IPerson {

public string? FirstName {
get {
return (string?) default;
}
set {
}
}
public string? LastName {
get {
return (string?) default;
}
set {
}
}
public string FullName() {
return (string) default;
}

}

Useful

Download Example (.NET C#)

Share DudNet

https://ignatandrei.github.io/RSCG_Examples/v2/docs/DudNet

aaa

Category "EnhancementClass" has the following generators:

1 ApparatusAOT Nuget GitHub Repo stars 2023-04-16

2 AspectGenerator Nuget GitHub Repo stars 2024-01-07

3 CommonCodeGenerator Nuget GitHub Repo stars 2024-04-03

4 Comparison Nuget GitHub Repo stars 2025-05-25

5 DudNet Nuget GitHub Repo stars 2023-10-27

6 Enhanced.GetTypes Nuget GitHub Repo stars 2024-09-17

7 FastGenericNew Nuget GitHub Repo stars 2023-08-10

8 Immutype Nuget GitHub Repo stars 2023-08-12

9 Ling.Audit Nuget GitHub Repo stars 2023-12-12

10 Lombok.NET Nuget GitHub Repo stars 2023-04-16

11 M31.FluentAPI Nuget GitHub Repo stars 2023-08-25

12 MemberAccessor Nuget GitHub Repo stars 2025-03-24

13 MemoryPack Nuget GitHub Repo stars 2023-08-04

14 Meziantou.Polyfill Nuget GitHub Repo stars 2023-10-10

15 Microsoft.Extensions.Logging Nuget GitHub Repo stars 2023-04-16

16 Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator Nuget GitHub Repo stars 2023-11-17

17 Microsoft.Interop.JavaScript.JSImportGenerator 2023-04-16

18 OptionToStringGenerator Nuget GitHub Repo stars 2024-02-15

19 Program Nuget GitHub Repo stars 2025-11-06

20 QueryStringGenerator Nuget GitHub Repo stars 2024-11-07

21 RSCG_Decorator Nuget GitHub Repo stars 2023-09-30

22 RSCG_UtilityTypes NugetNuget GitHub Repo stars 2023-12-22

23 StaticReflection NugetNuget GitHub Repo stars 2023-10-13

24 SyncMethodGenerator Nuget GitHub Repo stars 2023-08-14

25 System.Runtime.InteropServices Nuget GitHub Repo stars 2023-04-16

26 System.Text.RegularExpressions Nuget GitHub Repo stars 2023-04-16

27 TelemetryLogging Nuget GitHub Repo stars 2023-11-30

28 ThisClass Nuget GitHub Repo stars 2024-04-19

See category

EnhancementClass