Skip to main content

RSCG_UtilityTypes by Andrei Ignat

Nuget / site data

NugetNuget GitHub last commit GitHub Repo stars

Details

Info

Original Readme

note

RSCG_UtilityTypes

Omit and Pick from TypeScript : https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys

generating also extension for converting from one type to another . See demo project.

Usage

Add to your csproj file

  <ItemGroup>
<PackageReference Include="RSCG_UtilityTypes" Version="2023.1223.1230" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="RSCG_UtilityTypesCommon" Version="2023.1223.1230" />
</ItemGroup>

In C# 9.0

[Omit("MoviePreviewSmall", nameof(Actors),nameof(Year))]
[Pick("MoviePreviewMinimal", nameof(Title), nameof(Year))]
public class Movie
{
public string? Title { get; set; }
public string? Director { get; set; }
public int Year { get; set; }
public string[]? Actors { get; set; }
}

And 2 new classes will be generated , MoviePreviewSmall and MoviePreviewMinimal

About

note

Add omit and pick to selectively generate types from existing types

How to use

Example ( source csproj, source files )

This is the CSharp Project that references RSCG_UtilityTypes

<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>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

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;
}


}
}

Usefull

Download Example (.NET C# )

Share RSCG_UtilityTypes

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

In the same category (EnhancementClass) - 25 other generators

ApparatusAOT

AspectGenerator

CommonCodeGenerator

DudNet

Enhanced.GetTypes

FastGenericNew

HsuSgSync

Immutype

Ling.Audit

Lombok.NET

M31.FluentAPI

MemoryPack

Meziantou.Polyfill

Microsoft.Extensions.Logging

Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator

Microsoft.Interop.JavaScript.JSImportGenerator

OptionToStringGenerator

QueryStringGenerator

RSCG_Decorator

StaticReflection

SyncMethodGenerator

System.Runtime.InteropServices

System.Text.RegularExpressions

TelemetryLogging

ThisClass