{"id":13629263,"url":"https://github.com/jwshyns/DudNet","last_synced_at":"2025-04-17T08:34:36.743Z","repository":{"id":189611557,"uuid":"680957621","full_name":"jwshyns/DudNet","owner":"jwshyns","description":"Proxy-pattern source generator","archived":false,"fork":false,"pushed_at":"2023-10-24T03:18:18.000Z","size":44,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-12T12:41:52.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwshyns.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-08-21T00:10:07.000Z","updated_at":"2024-03-23T14:15:28.000Z","dependencies_parsed_at":"2024-01-06T02:10:00.914Z","dependency_job_id":null,"html_url":"https://github.com/jwshyns/DudNet","commit_stats":null,"previous_names":["jwshyns/dudnet"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwshyns%2FDudNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwshyns%2FDudNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwshyns%2FDudNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwshyns%2FDudNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwshyns","download_url":"https://codeload.github.com/jwshyns/DudNet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249326186,"owners_count":21251735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T22:01:06.036Z","updated_at":"2025-04-17T08:34:36.491Z","avatar_url":"https://github.com/jwshyns.png","language":"C#","readme":"﻿# DudNet [![NuGet Badge](https://buildstats.info/nuget/Jwshyns.DudNet)](https://www.nuget.org/packages/Jwshyns.DudNet)\n \nDudNet is a C# source generator for implementing a proxy pattern. \n\n## Example\n\nGenerating a proxy for a class is as simple as marking it with the `ProxyServiceAttribute` as follows:\n```csharp\nusing DudNet.Attributes;\n\npublic interface IExampleService {\n    \n       public void ExampleFunction();\n    \n       public int ExampleFunctionWithArgumentAndReturn(int number);\n    \n}\n\n[ProxyService]\npublic class ExampleService : IExampleService {\n    \n       public void ExampleFunction(){\n           // omitted for brevity\n       }\n        \n       public int ExampleFunctionWithArgumentAndReturn(int number){\n           // omitted for brevity\n       }\n    \n       public void FunctionNotOnInterface(){\n           // ommitted for brevity\n       }\n    \n}\n```\n\nWhich would generate the following two classes:\n```csharp\nusing System.Runtime.CompilerServices;\nusing DudNet.Attributes;\n\npublic partial class ExampleServiceProxy : IExampleService {\n\n\tprivate readonly IExampleService _service;\n\n\tpublic void ExampleFunction() {\n\t\tInterceptor();\n\t\tExampleFunctionInterceptor();\n\t\t_service.ExampleFunction();\n\t}\n    \n\tpublic int ExampleFunctionWithArgumentAndReturn(int number) {\n\t\tInterceptor();\n\t\tExampleFunctionWithArgumentAndReturnInterceptor(number);\n\t\t_service.ExampleFunctionWithArgumentAndReturn(number);\n\t}\n    \n\tpartial void Interceptor([CallerMemberName]string callerName = null);\n\n\tpartial void ExampleFunctionInterceptor();\n\n\tpartial void ExampleFunctionWithArgumentAndReturnInterceptor(int number);\n}\n```\nand \n```csharp\nusing DudNet.Attributes;\n\npublic class ExampleServiceDud : IExampleService {\n\n    public void ExampleFunction() {\n    }\n    \n    public int ExampleFunctionWithArgumentAndReturn(int number) {\n    }\n\n}\n```\n\nThese generated classes can be used by further implementing the `partial` proxy class as follows:\n```csharp\npublic partial class ExampleServiceProxy : IExampleService {\n    \n    public ExampleServiceProxy(ExampleProxyService service) {\n        // Some logic to determine whether you want to effectively \"disable\" the service\n        if (Random.Shared.NextDouble() \u003e 0.5)\n        { \n            _service = service;\n            return;\n        }\n        \n        _service = new ExampleServiceDud();\n    }\n    \n    partial void Interceptor([CallerMemberName]string callerName = null) {\n        Console.Writeline(\"'{caller}' was called\", callerName);\n    }   \n    \n    partial void ExampleFunctionWithArgumentAndReturnInterceptor(int number) {\n        if(number \u003e 5) \n        {\n            throw new Exception(\"Received number value '{number}' - too high!\", number);\n        }\n    }\n\n}\n\n```\n","funding_links":[],"categories":["Content","Source Generators"],"sub_categories":["79. [DudNet](https://ignatandrei.github.io/RSCG_Examples/v2/docs/DudNet) , in the [EnhancementClass](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementclass) category","Patterns"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwshyns%2FDudNet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwshyns%2FDudNet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwshyns%2FDudNet/lists"}