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


}
}

Useful

Download Example (.NET C#)

Share RSCG_UtilityTypes

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

aaa

Category "EnhancementClass" has the following generators:

1 ApparatusAOT

2 AspectGenerator

3 CommonCodeGenerator

4 Comparison

5 DudNet

6 Enhanced.GetTypes

7 FastGenericNew

8 Immutype

9 Ling.Audit

10 Lombok.NET

11 M31.FluentAPI

12 MemberAccessor

13 MemoryPack

14 Meziantou.Polyfill

15 Microsoft.Extensions.Logging

16 Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator

17 Microsoft.Interop.JavaScript.JSImportGenerator

18 OptionToStringGenerator

19 QueryStringGenerator

20 RSCG_Decorator

21 RSCG_UtilityTypes

22 StaticReflection

23 SyncMethodGenerator

24 System.Runtime.InteropServices

25 System.Text.RegularExpressions

26 TelemetryLogging

27 ThisClass

See category

EnhancementClass