Skip to main content

rscg_Interface_to_null_object by Andrei Ignat

Nuget / site data

NugetNuget GitHub last commit GitHub Repo stars

Details

Info

Original Readme

note

NuGet version

NuGet version

Interface to Null Object Pattern

Implementation of https://en.wikipedia.org/wiki/Null_object_pattern from interface

Installation

Add to your csproj file:

  <ItemGroup>
<PackageReference Include="rscg_Interface_to_null_object" Version="2025.120.1832" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="rscg_Interface_to_null_object_common" Version="2025.120.1832" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

Or add the nuget packages rscg_Interface_to_null_object and rscg_Interface_to_null_object_common

Usage

[InterfaceToNullObject.ToNullObject]
public interface IEmployee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public IDepartment Department { get; set; }
public string GetFullName();

}

And then a C# class that implements the interface will be generated

public partial class Employee_null : global::IntegrationConsole.IEmployee
{

public virtual string FirstName { get; set; } = default(string);

public virtual string LastName { get; set; } = default(string);

public virtual IntegrationConsole.IDepartment Department { get; set; } = default(IntegrationConsole.IDepartment);

public virtual string GetFullName() { return default(string); }

}

About

note

Generate null objects for interfaces

How to use

Example ( source csproj, source files )

This is the CSharp Project that references rscg_Interface_to_null_object

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

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

<ItemGroup>
<PackageReference Include="rscg_Interface_to_null_object" Version="2025.120.1832" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="rscg_Interface_to_null_object_common" Version="2025.120.1832" />
</ItemGroup>

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX


// <auto-generated/>
namespace Generated.NullInterface
{
public static class TheAssemblyInfo
{

public static readonly System.DateTime DateGeneratedUTC ;
public const string AssemblyName = "NullInterface";
public const string GeneratedNameNice = "Nadine Gordimer is feeling rational in Seoul";
public const string GeneratedNameSmall = "rational-Nadine Gordimer";
public const string GeneratedName = "rational-Nadine Gordimer-Seoul";
static TheAssemblyInfo(){
DateGeneratedUTC = System.DateTime.ParseExact("2025-01-21 13:29:00", "yyyy-MM-dd HH:mm:ss", null);
}
}
}

Usefull

Download Example (.NET C# )

Share rscg_Interface_to_null_object

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

In the same category (Interface) - 10 other generators

Biwen.AutoClassGen

CopyCat

Farskeptic.AutoCompose

MakeInterface.Generator

Matryoshki

Minerals.AutoInterfaces

NetAutomaticInterface

ProxyGen

Roozie.AutoInterface

RSCG_Static