Skip to main content

RSCG_Static by Andrei Ignat

NuGet / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: RSCG_Static

This package make you an interface and record from static properties / methods

Author: Andrei Ignat

NuGet: https://www.nuget.org/packages/RSCG_Static/

You can find more details at https://github.com/ignatandrei/RSCG_Static

Source: https://github.com/ignatandrei/RSCG_Static

Original Readme

note

RSCG_Static

Roslyn Source Code Generator - transform static classes into instances and interfaces

More, there is a MakeNew static method created to can have DI.

Just put a function like this ( example for System.DateTime)

        public Type GenerateInterfaceFromDate()=>typeof(DateTime);

and the properties of the classes will be generated into interfaces and you can write:

//for DI, register
//ISystem_DateTime with transient for new clsSystem_DateTime()
Console.WriteLine("Hello World!");
ISystem_DateTime dateStatic = recSystem_DateTime.MakeNew();//static
ISystem_DateTime dateVar = new clsSystem_DateTime(); //variable = real

Console.WriteLine(dateStatic.Now.Second);
Console.WriteLine(dateVar.Now.Second);
await Task.Delay(10 * 1000);
Console.WriteLine(dateStatic.Now.Second);
Console.WriteLine(dateVar.Now.Second);

More Roslyn Source Code Generators

You can find more RSCG with examples at Roslyn Source Code Generators

About

note

Generate interfaces and classes from static classes

How to use

Example (source csproj, source files)

This is the CSharp Project that references RSCG_Static

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RSCG_Static" Version="2023.5.19.2037" />
</ItemGroup>

</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX


#nullable enable
namespace RSCG_StaticDemo {
public interface ISystem_DateTime {
public System.DateTime Now {get;}
public System.DateTime Today {get;}
public System.DateTime UtcNow {get;}
}// interface
//now the partial class
public record recSystem_DateTime (System.DateTime Now,System.DateTime Today,System.DateTime UtcNow) : ISystem_DateTime
{
public static recSystem_DateTime MakeNew() {
return new recSystem_DateTime(System.DateTime.Now,System.DateTime.Today,System.DateTime.UtcNow);
} //end makenew
} //end record
public class clsSystem_DateTime : ISystem_DateTime
{
public System.DateTime Now {get { return System.DateTime.Now; } }
public System.DateTime Today {get { return System.DateTime.Today; } }
public System.DateTime UtcNow {get { return System.DateTime.UtcNow; } }
} //end class
} // namespace
#nullable disable

Useful

Download Example (.NET C# )

Share RSCG_Static

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

In the same category (Interface) - 11 other generators

Biwen.AutoClassGen

CopyCat

Farskeptic.AutoCompose

MakeInterface.Generator

Matryoshki

Minerals.AutoInterfaces

NetAutomaticInterface

ProxyGen

Roozie.AutoInterface

RSCG_CompositeProvider

rscg_Interface_to_null_object