{"id":25019623,"url":"https://github.com/ignatandrei/rscg_interface_to_null_object","last_synced_at":"2026-03-11T13:13:11.564Z","repository":{"id":273084479,"uuid":"918661010","full_name":"ignatandrei/rscg_Interface_to_null_object","owner":"ignatandrei","description":"Implementation of https://en.wikipedia.org/wiki/Null_object_pattern  from interface","archived":false,"fork":false,"pushed_at":"2025-05-19T19:29:25.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-11T12:36:53.070Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ignatandrei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-18T14:26:03.000Z","updated_at":"2025-05-19T19:29:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"d4ef19a2-40ef-4e4e-8a14-2e2485573d0e","html_url":"https://github.com/ignatandrei/rscg_Interface_to_null_object","commit_stats":null,"previous_names":["ignatandrei/rscg_interface_to_null_object"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/ignatandrei/rscg_Interface_to_null_object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2Frscg_Interface_to_null_object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2Frscg_Interface_to_null_object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2Frscg_Interface_to_null_object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2Frscg_Interface_to_null_object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ignatandrei","download_url":"https://codeload.github.com/ignatandrei/rscg_Interface_to_null_object/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2Frscg_Interface_to_null_object/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30382553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T12:49:11.341Z","status":"ssl_error","status_checked_at":"2026-03-11T12:46:41.342Z","response_time":84,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-02-05T11:51:14.588Z","updated_at":"2026-03-11T13:13:11.559Z","avatar_url":"https://github.com/ignatandrei.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NuGet version](https://img.shields.io/nuget/v/rscg_Interface_to_null_object.svg?style=flat-square)](https://www.nuget.org/packages/rscg_Interface_to_null_object)\n\n[![NuGet version](https://img.shields.io/nuget/v/rscg_Interface_to_null_object_common.svg?style=flat-square)](https://www.nuget.org/packages/rscg_Interface_to_null_object_common)\n\n\n# Interface to Null Object Pattern\nImplementation of https://en.wikipedia.org/wiki/Null_object_pattern  from interface\n\n# Installation\n\nAdd to your csproj file:\n\n```xml\n  \u003cItemGroup\u003e\n    \u003cPackageReference Include=\"rscg_Interface_to_null_object\" Version=\"2025.519.1000\"  OutputItemType=\"Analyzer\" ReferenceOutputAssembly=\"false\"  /\u003e\n    \u003cPackageReference Include=\"rscg_Interface_to_null_object_common\" Version=\"2025.519.1000\" /\u003e\n  \u003c/ItemGroup\u003e\n\t\u003cPropertyGroup\u003e\n\t\t\u003cEmitCompilerGeneratedFiles\u003etrue\u003c/EmitCompilerGeneratedFiles\u003e\n\t\t\u003cCompilerGeneratedFilesOutputPath\u003e$(BaseIntermediateOutputPath)\\GX\u003c/CompilerGeneratedFilesOutputPath\u003e\n\t\u003c/PropertyGroup\u003e\n```\n\nOr add the nuget packages rscg_Interface_to_null_object  and rscg_Interface_to_null_object_common\n\n# Usage\n\n## Simple usage\n```csharp\n[InterfaceToNullObject.ToNullObject]\npublic interface IEmployee\n{\n    public string FirstName { get; set; }\n    public string LastName { get; set; }\n    public IDepartment Department { get; set; }\n    public string GetFullName();\n  \n}\n```\n\nAnd then a C# class that implements the interface will be generated\n\n```csharp\npublic partial class Employee_null : global::IntegrationConsole.IEmployee\n{\n\n        public virtual string FirstName { get; set; } = default(string);\n    \n        public virtual string LastName { get; set; } = default(string);\n    \n        public virtual IntegrationConsole.IDepartment Department { get; set; } = default(IntegrationConsole.IDepartment);\n    \n        public virtual string GetFullName() { return default(string); }\n    \n}\n\n```\n## Deserialize to interface\n\nSee following code that deserializes to interface with a converter that is automatically generated\n\n```csharp\n//serialize and deserialize\nvar empString = JsonSerializer.Serialize(employee);\nConsole.WriteLine(empString);\n//deserialize\n\nvar options = new JsonSerializerOptions\n{\n    PropertyNameCaseInsensitive = true,\n    DefaultBufferSize = 128\n};\noptions.Converters.Add(new IDepartmentConverter());\noptions.Converters.Add(new IEmployeeConverter());\n\nvar emp2 = JsonSerializer.Deserialize\u003cIEmployee\u003e(empString,options);\nArgumentNullException.ThrowIfNull(emp2);\nConsole.WriteLine(emp2.FirstName);\nConsole.WriteLine(emp2.Department.Name);\nDebug.Assert(emp2.FirstName == \"Andrei\");\n```\n\n\n## Adding default values\n\nLet's say you want to return an empty string for the GetFullName method, you can add the following code to your csproj file\n\n```xml\n\u003cItemGroup\u003e\n  \u003cCompilerVisibleProperty Include=\"I2NO_String\" /\u003e\n\u003c/ItemGroup\u003e\n\u003cPropertyGroup\u003e\n  \u003cI2NO_String\u003ereturn \"\"\u003c/I2NO_String\u003e\t\n\u003c/PropertyGroup\u003e\n```\n\nSo now the code will be generated like this\n\n```csharp\npublic virtual string GetFullName() {  return \"\" ; }\n```\n\nFor array and generics, see \n```xml\n\u003cItemGroup\u003e\n\t\u003cCompilerVisibleProperty Include=\"I2NO_String\" /\u003e\n\t\u003cCompilerVisibleProperty Include=\"I2NO_IntegrationConsole_IEmployee_Array\" /\u003e\n\t\u003cCompilerVisibleProperty Include=\"I2NO_System_Collections_Generic_IAsyncEnumerable_Of_IntegrationConsole_IEmployee_EndOf\" /\u003e\n\u003c/ItemGroup\u003e\n\u003cItemGroup\u003e\n  \u003cPackageReference Include=\"System.Linq.Async\" Version=\"6.0.1\" /\u003e\n\u003c/ItemGroup\u003e\n\u003cPropertyGroup\u003e\n\t\u003cI2NO_String\u003ereturn \"\"\u003c/I2NO_String\u003e\n\t\u003cI2NO_IntegrationConsole_IEmployee_Array\u003ereturn []\u003c/I2NO_IntegrationConsole_IEmployee_Array\u003e\n\t\u003cI2NO_System_Collections_Generic_IAsyncEnumerable_Of_IntegrationConsole_IEmployee_EndOf\u003ereturn AsyncEnumerable.Empty_Of_IntegrationConsole.IEmployee_EndOf();\u003c/I2NO_System_Collections_Generic_IAsyncEnumerable_Of_IntegrationConsole_IEmployee_EndOf\u003e\n\u003c/PropertyGroup\u003e\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignatandrei%2Frscg_interface_to_null_object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fignatandrei%2Frscg_interface_to_null_object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignatandrei%2Frscg_interface_to_null_object/lists"}