RSCG – MorrisMoxy

RSCG – MorrisMoxy
 
 

name MorrisMoxy
nuget https://www.nuget.org/packages/Morris.Moxy/
link https://github.com/mrpmorris/Morris.Moxy
author Peter Morris

Generate C# code for classes from template using attributes

 

This is how you can use MorrisMoxy .

The code that you start with is


<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>
    <None Remove="mixin\IDName.mixin" />
  </ItemGroup>

  <ItemGroup>
    <AdditionalFiles Include="mixin\IDName.mixin" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Morris.Moxy" Version="1.5.0" OutputItemType="Analyzer" ReferenceOutputAssembly="false"  />
  </ItemGroup>

</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using MorrisMoxyDemo;
var e = new Employee();
e.Name = "Andrei";
var d = new Department();
d.Name = "IT";
Console.WriteLine(e.ID);




namespace MorrisMoxyDemo;
[IDName]
partial class Employee
{
}




namespace MorrisMoxyDemo;
[IDName]
partial class Department
{
}


 

The code that is generated is

// Generated from mixin\IDName.mixin at 2023-07-31 19:27:42 UTC
namespace MorrisMoxyDemo
{
    
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)]
    internal class IDNameAttribute : Attribute
    {
    }
}


// Generated at 2023-07-31 19:27:42 UTC
namespace MorrisMoxyDemo
{
  partial class Department
  {
    public string Name {get;set;}
    public long  ID { get; set; }
  }
}

// Generated at 2023-07-31 19:27:42 UTC
namespace MorrisMoxyDemo
{
  partial class Employee
  {
    public string Name {get;set;}
    public long  ID { get; set; }
  }
}

Code and pdf at

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