RSCG – RSCG_UtilityTypes
RSCG – RSCG_UtilityTypes
name | RSCG_UtilityTypes |
nuget |
https://www.nuget.org/packages/RSCG_UtilityTypes/ https://www.nuget.org/packages/RSCG_UtilityTypesCommon |
link | https://github.com/ignatandrei/RSCG_UtilityTypes |
author | Andrei Ignat |
Add omit and pick to selectively generate types from existing types
This is how you can use RSCG_UtilityTypes .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <PackageReference Include="RSCG_UtilityTypes" Version="2023.1223.1230" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> <PackageReference Include="RSCG_UtilityTypesCommon" Version="2023.1223.1230" /> </ItemGroup> <PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> </PropertyGroup> </Project>
The code that you will use is
using UtilDemo; var p=new PersonFull(); p.FirstName="Andrei"; p.LastName="Ignat"; Person1 p1=(Person1)p ; Person2 p2=(Person2)p ; Console.WriteLine(p1.FirstName); Console.WriteLine(p2.LastName);
using RSCG_UtilityTypesCommon; namespace UtilDemo; [Pick("Person1",nameof(FirstName),nameof(LastName))] [Omit("Person2", nameof(Salary))] public class PersonFull { public string FirstName { get; set; } public string LastName { get; set; } public int Salary { get; set; } }
The code that is generated is
namespace UtilDemo { partial class Person1 { public string FirstName { get; set; } public string LastName { get; set; } public static explicit operator Person1(PersonFull data ) { var ret= new Person1 (); ret.FirstName = data.FirstName; ret.LastName = data.LastName; return ret; } public static explicit operator PersonFull(Person1 data ) { var ret= new PersonFull (); ret.FirstName = data.FirstName; ret.LastName = data.LastName; return ret; } } }
namespace UtilDemo { partial class Person2 { public string FirstName { get; set; } public string LastName { get; set; } public static explicit operator Person2(PersonFull data ) { var ret= new Person2 (); ret.FirstName = data.FirstName; ret.LastName = data.LastName; return ret; } public static explicit operator PersonFull(Person2 data ) { var ret= new PersonFull (); ret.FirstName = data.FirstName; ret.LastName = data.LastName; return ret; } } }
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_UtilityTypes
Leave a Reply