RSCG – rscg_demeter

RSCG – rscg_demeter    

name rscg_demeter
nuget https://www.nuget.org/packages/rscg_demeter/
link https://github.com/ignatandrei/rscg_demeter/
author Andrei Ignat

Generating diagnostics about Law of Demeter violations

 

This is how you can use rscg_demeter .

The code that you start with is

  <Project Sdk="Microsoft.NET.Sdk">  	<PropertyGroup> 		<OutputType>Exe</OutputType> 		<TargetFramework>net9.0</TargetFramework> 		<ImplicitUsings>enable</ImplicitUsings> 		<Nullable>enable</Nullable> 		<IsPackable>false</IsPackable> 		<TreatWarningsAsErrors>true</TreatWarningsAsErrors> 		<WarningsNotAsErrors>CS0436,NU1903</WarningsNotAsErrors>  	</PropertyGroup>  	<ItemGroup> 		<CompilerVisibleProperty Include="RSCG_Demeter_GenerateFile" /> 	</ItemGroup>  	<PropertyGroup> 		<RSCG_Demeter_GenerateFile>obj/gx/RSCG_Console.csproj.txt</RSCG_Demeter_GenerateFile> 	</PropertyGroup>   <ItemGroup>     <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.3" />     <PackageReference Include="RSCG_Demeter" Version="2026.328.706" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />   </ItemGroup>    	<PropertyGroup> 		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> 		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> 	</PropertyGroup> </Project>   

The code that you will use is

  // See https://aka.ms/new-console-template for more information using RSCG_Console;  Console.WriteLine("Hello, World!"); var dep = new Department(); dep.Employees.Add(new Employee());  foreach (var emp in dep.Employees) {     dep.EmployeeNames.Add(emp.Name); } var empAll = dep.Employees; var empWithA = empAll.Where(it => it.Name.StartsWith("a")); await Task.Run(dep.GetEmployees); var asda = new List<int>(empAll.Select(it => it.ID).Distinct().OrderBy(it => it)); Console.WriteLine(asda.Count); List<string> data = []; var d = AppDomain.CurrentDomain.GetAssemblies()     .Where(it => data.Any(a => !(it.FullName?.StartsWith(a) ?? false)))     .Distinct()     .ToArray();  var builder = new EmpBuilder().SetName("Ignat").SetId(1).SetName("Andrei"); var emp1 =builder.BuildEmployee();  

  The code that is generated is

 {   "dateGenerator": "20250329050839",   "nameGenerator": "Gerhart Hauptmann is feeling agreeable in Porto-Novo",   "maxDemeterDots": 3,   "locationsFound": 5,   "DemeterLocations": [     {       "id": 1,       "startLine": 5,       "nrDots": 2,       "endLine": 5,       "filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs",       "text": "dep.Employees.Add(new Employee())"     },     {       "id": 2,       "startLine": 9,       "nrDots": 2,       "endLine": 9,       "filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs",       "text": "    dep.EmployeeNames.Add(emp.Name)"     },     {       "id": 3,       "startLine": 12,       "nrDots": 2,       "endLine": 12,       "filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs",       "text": "it.Name.StartsWith(\u0022a\u0022)"     },     {       "id": 4,       "startLine": 14,       "nrDots": 2,       "endLine": 14,       "filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs",       "text": "empAll.Select(it =\u003E it.ID).Distinct().OrderBy(it =\u003E it)"     },     {       "id": 5,       "startLine": 17,       "nrDots": 3,       "endLine": 20,       "filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs",       "text": "AppDomain.CurrentDomain.GetAssemblies()\r\n    .Where(it =\u003E data.Any(a =\u003E !(it.FullName?.StartsWith(a) ?? false)))\r\n    .Distinct()\r\n    .ToArray()"     }   ] } 

Code and pdf at https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg_demeter

RSCG – PMart.Enumeration

RSCG – PMart.Enumeration    

name PMart.Enumeration
nuget https://www.nuget.org/packages/PMart.Enumeration.Generator/ https://www.nuget.org/packages/PMart.Enumeration/
link https://github.com/p-martinho/Enumeration
author Martinho

Constants as enumeration. With EFCore, Swagger and other implementations.

 

This is how you can use PMart.Enumeration .

The code that you start with is

  <Project Sdk="Microsoft.NET.Sdk">  	<PropertyGroup> 		<OutputType>Exe</OutputType> 		<TargetFramework>net9.0</TargetFramework> 		<ImplicitUsings>enable</ImplicitUsings> 		<Nullable>enable</Nullable> 	</PropertyGroup> 	<ItemGroup>  		<PackageReference Include="PMart.Enumeration" Version="3.1.0" /> 		<PackageReference Include="PMart.Enumeration.Generator" Version="3.1.0" PrivateAssets="all" ExcludeAssets="runtime" />  	</ItemGroup> 	<PropertyGroup> 		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> 		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> 	</PropertyGroup> </Project>   

The code that you will use is

  using DemoPMart;  var personType= PersonType.GetFromValueOrDefault("test"); Console.WriteLine(personType?.Value??"null"); personType = PersonType.GetFromValueOrDefault("manager"); Console.WriteLine(personType!.Value); Console.WriteLine(PersonType.Manager == personType);   
  using PMart.Enumeration.Generator.Attributes;  namespace DemoPMart; [Enumeration] public partial class PersonType {     private static readonly string ValueForEmployee = "Employee";     private static readonly string ValueForManager = "Manager";   }   

  The code that is generated is

 // <auto-generated> //     This code was generated by the PMart.Enumeration.Generator source generator. // </auto-generated>  #nullable enable  namespace DemoPMart {     public partial class PersonType : global::PMart.Enumeration.Enumeration<global::DemoPMart.PersonType>     {         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("PMart.Enumeration.Generator", "3.1.0.0")]         public static readonly global::DemoPMart.PersonType Employee = new global::DemoPMart.PersonType(ValueForEmployee!);          [global::System.CodeDom.Compiler.GeneratedCodeAttribute("PMart.Enumeration.Generator", "3.1.0.0")]         public static readonly global::DemoPMart.PersonType Manager = new global::DemoPMart.PersonType(ValueForManager!);          [global::System.CodeDom.Compiler.GeneratedCodeAttribute("PMart.Enumeration.Generator", "3.1.0.0")]         private PersonType(string value) : base(value)         {         }     } } 

Code and pdf at https://ignatandrei.github.io/RSCG_Examples/v2/docs/PMart.Enumeration

RSCG – MemberAccessor

RSCG – MemberAccessor    

name MemberAccessor
nuget https://www.nuget.org/packages/BunnyTail.MemberAccessor/
link https://github.com/usausa/member-accessor-generator
author Yamaokuno

Generate getter and setter for class members.

 

This is how you can use MemberAccessor .

The code that you start with is

  <Project Sdk="Microsoft.NET.Sdk">    <PropertyGroup>     <OutputType>Exe</OutputType>     <TargetFramework>net9.0</TargetFramework>     <ImplicitUsings>enable</ImplicitUsings>     <Nullable>enable</Nullable>   </PropertyGroup> 	<ItemGroup> 		<PackageReference Include="BunnyTail.MemberAccessor" Version="1.2.0" /> 	</ItemGroup> 	<PropertyGroup> 		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> 		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> 	</PropertyGroup> </Project>   

The code that you will use is

  using BunnyTail.MemberAccessor; using DemoMember;  var accessorFactory = AccessorRegistry.FindFactory<Person>(); ArgumentNullException.ThrowIfNull(accessorFactory); var getter = accessorFactory.CreateGetter<string>(nameof(Person.FirstName)); var setter = accessorFactory.CreateSetter<string>(nameof(Person.FirstName)); ArgumentNullException.ThrowIfNull(getter); ArgumentNullException.ThrowIfNull(setter); var p= new Person(); setter(p, "andrei"); Console.WriteLine(getter(p));  
  using BunnyTail.MemberAccessor;  namespace DemoMember; [GenerateAccessor] internal class Person {     public string FirstName { get; set; }=string.Empty; }   

  The code that is generated is

 // <auto-generated /> #nullable enable  internal static class AccessorFactoryInitializer {     [global::System.Runtime.CompilerServices.ModuleInitializer]     public static void Initialize()     {         global::BunnyTail.MemberAccessor.AccessorRegistry.RegisterFactory(typeof(global::DemoMember.Person), typeof(global::DemoMember.Person_AccessorFactory));     } }  
 // <auto-generated /> #nullable enable  namespace DemoMember;  internal sealed class Person_AccessorFactory : global::BunnyTail.MemberAccessor.IAccessorFactory<global::DemoMember.Person> {     private static readonly global::System.Func<object, object?> ObjectFirstNameGetter = static x => ((global::DemoMember.Person)x).FirstName!;      private static readonly global::System.Action<object, object?> ObjectFirstNameSetter = static (x, v) => ((global::DemoMember.Person)x).FirstName = (string)v!;      private static readonly global::System.Func<global::DemoMember.Person, string> TypedFirstNameGetter = static x => x.FirstName;      private static readonly global::System.Action<global::DemoMember.Person, string> TypedFirstNameSetter = static (x, v) => x.FirstName = v;      public global::System.Func<object, object?>? CreateGetter(string name)     {         if (name == "FirstName") return ObjectFirstNameGetter;         return null;     }      public global::System.Action<object, object?>? CreateSetter(string name)     {         if (name == "FirstName") return ObjectFirstNameSetter;         return null;     }      public global::System.Func<global::DemoMember.Person, TProperty>? CreateGetter<TProperty>(string name)     {         if (name == "FirstName") return (global::System.Func<global::DemoMember.Person, TProperty>)(object)TypedFirstNameGetter;         return null;     }      public global::System.Action<global::DemoMember.Person, TProperty>? CreateSetter<TProperty>(string name)     {         if (name == "FirstName") return (global::System.Action<global::DemoMember.Person, TProperty>)(object)TypedFirstNameSetter;         return null;     } }  

Code and pdf at https://ignatandrei.github.io/RSCG_Examples/v2/docs/MemberAccessor

RSCG – StepwiseBuilderGenerator

RSCG – StepwiseBuilderGenerator    

name StepwiseBuilderGenerator
nuget https://www.nuget.org/packages/StepwiseBuilderGenerator/
link https://github.com/Georgiy-Petrov/StepwiseBuilderGenerator
author Georgiy Petrov

Generating Builder- as steps

 

This is how you can use StepwiseBuilderGenerator .

The code that you start with is

  <Project Sdk="Microsoft.NET.Sdk">    <PropertyGroup>     <OutputType>Exe</OutputType>     <TargetFramework>net8.0</TargetFramework> 	  <Nullable>enable</Nullable>   </PropertyGroup>  	  <PropertyGroup>         <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>         <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>     </PropertyGroup>  	  <ItemGroup> 	    <PackageReference Include="StepwiseBuilderGenerator" Version="1.0.3" /> 	  </ItemGroup>  	   	   </Project>   

The code that you will use is

  using Builder;  var pOld = new Person(); pOld.MiddleName = "G"; var pNew= pOld     .SetFirstNameBld("Andrei")     .SetLastNameBuilder("Ignat")     .Age(55)     .Build(it=>it)     ;    //var build = new PersonBuilder() //    .WithFirstName(pOld.FirstName) //    //.WithMiddleName("") // it is not into the constructor //    .WithLastName(pOld.LastName) //    ;      //var pNew = build.Build(); System.Console.WriteLine(pNew.FullName()); System.Console.WriteLine(pOld.FullName());   
  using StepwiseBuilderGenerator; using System;  namespace Builder; [StepwiseBuilder] public partial class Person {     public Person()     {         new GenerateStepwiseBuilder()            .AddStep<string>("SetFirstNameBld", "FirstName")            .AddStep<string>("SetLastNameBuilder", "LastName")            .AddStep<int>("Age")              .CreateBuilderFor<Person>();     }     //public Person(string firstName, string lastName)     //{     //    FirstName = firstName;     //    LastName = lastName;     //}     //public string FirstName { get; set; }     public string? MiddleName { get; set; }     //public string LastName { get; set; }      public string FullName()     {         return FirstName + " " + MiddleName + " "+LastName;     }      }   

  The code that is generated is

 using StepwiseBuilderGenerator; using System;  namespace Builder; public interface IPersonSetFirstNameBld  {     IPersonSetLastNameBuilder SetFirstNameBld(string value); } public interface IPersonSetLastNameBuilder  {     IPersonAge SetLastNameBuilder(string value); } public interface IPersonAge  {     IPersonBuild Age(int value); } public interface IPersonBuild  {     Person Build(Func<Person, Person> buildFunc); } public partial class Person : IPersonSetFirstNameBld,IPersonSetLastNameBuilder,IPersonAge,IPersonBuild  {    public string FirstName;     public string LastName;     public int AgeValue;      public IPersonSetLastNameBuilder SetFirstNameBld(string value)     {         FirstName = value;         return this;     }     public IPersonAge SetLastNameBuilder(string value)     {         LastName = value;         return this;     }     public IPersonBuild Age(int value)     {         AgeValue = value;         return this;     }     public Person Build(Func<Person, Person> buildFunc)     {         return buildFunc(this);     }      public enum Steps     {         SetFirstNameBld,         SetLastNameBuilder,         Age,     } } public static partial class StepwiseBuilders {     public static IPersonSetFirstNameBld Person()      {          return new Person();     } }  

Code and pdf at https://ignatandrei.github.io/RSCG_Examples/v2/docs/StepwiseBuilderGenerator

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.