Category: RSCG

RSCG – GoLive.Generator.BlazorInterop

RSCG – GoLive.Generator.BlazorInterop
 
 

name GoLive.Generator.BlazorInterop
nuget https://www.nuget.org/packages/GoLive.Generator.BlazorInterop/
link https://github.com/surgicalcoder/BlazorInteropGenerator
author surgicalcoder

Generating interop from C# to javascript for Blazor

 

This is how you can use GoLive.Generator.BlazorInterop .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="GoLive.Generator.BlazorInterop" Version="2.0.7">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0-rc.2.24474.3" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0-rc.2.24474.3" PrivateAssets="all" />
  </ItemGroup>
	
	<ItemGroup>
		<AdditionalFiles Include="BlazorInterop.json" />
	</ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>


</Project>


The code that you will use is


{
  "Files": [
    {
      "Output_DeleteThis_ToHave_InYourProject": "JSInterop.cs",
      "ClassName": "JSInterop",
      "Source": "wwwroot\\blazorinterop.js",
      "Namespace": "GoLive.Generator.BlazorInterop.Playground.Client",
      "ObjectToInterop": "window.blazorInterop",
      "Init": ["window={}"]
    }
  ],
  "InvokeVoidString": "await JSRuntime.InvokeVoidAsync(\"{0}\", {1});",
  "InvokeString": "return await JSRuntime.InvokeAsync<T>(\"{0}\",{1});"
}



window.blazorInterop = {
    showModal: function (dialogId) {
        window.alert('see after this the page title'+dialogId);
        return true;
    },
    setPageTitle: function(title) {
        document.title = title;
    },    
};


@page "/"

@inject IJSRuntime JS

<PageTitle>Home</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private async Task IncrementCount()
    {
        currentCount++;
        var res= await JS.showModalAsync<bool>(currentCount);
        await JS.setPageTitleVoidAsync($" after {currentCount}  the result is " + res);
    }
}



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>MyTestBlazoe</title>
    <base href="/" />
    <link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="css/app.css" />
    <link rel="icon" type="image/png" href="favicon.png" />
    <link href="MyTestBlazoe.styles.css" rel="stylesheet" />
    <script src="blazorinterop.js" ></script>
</head>

<body>
    <div id="app">
        <svg class="loading-progress">
            <circle r="40%" cx="50%" cy="50%" />
            <circle r="40%" cx="50%" cy="50%" />
        </svg>
        <div class="loading-progress-text"></div>
    </div>

    <div id="blazor-error-ui">
        An unhandled error has occurred.
        <a href="." class="reload">Reload</a>
        <span class="dismiss">🗙</span>
    </div>
    <script src="_framework/blazor.webassembly.js"></script>
</body>

</html>


 

The code that is generated is

using System.Threading.Tasks;
using Microsoft.JSInterop;

namespace GoLive.Generator.BlazorInterop.Playground.Client
{
    public static class JSInterop
    {
        public static string _window_blazorInterop_showModal => "window.blazorInterop.showModal";

        public static async Task showModalVoidAsync(this IJSRuntime JSRuntime, object @dialogId)
        {
            await JSRuntime.InvokeVoidAsync("window.blazorInterop.showModal", @dialogId);
        }

        public static async Task<T> showModalAsync<T>(this IJSRuntime JSRuntime, object @dialogId)
        {
            return await JSRuntime.InvokeAsync<T>("window.blazorInterop.showModal", @dialogId);
        }

        public static string _window_blazorInterop_setPageTitle => "window.blazorInterop.setPageTitle";

        public static async Task setPageTitleVoidAsync(this IJSRuntime JSRuntime, object @title)
        {
            await JSRuntime.InvokeVoidAsync("window.blazorInterop.setPageTitle", @title);
        }

        public static async Task<T> setPageTitleAsync<T>(this IJSRuntime JSRuntime, object @title)
        {
            return await JSRuntime.InvokeAsync<T>("window.blazorInterop.setPageTitle", @title);
        }
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/GoLive.Generator.BlazorInterop

RSCG – Hsu.Sg.FluentMember

RSCG – Hsu.Sg.FluentMember
 
 

name Hsu.Sg.FluentMember
nuget https://www.nuget.org/packages/Hsu.Sg.FluentMember/
link https://github.com/hsu-net/source-generators
author Net Hsu

Adding builder pattern to classes

 

This is how you can use Hsu.Sg.FluentMember .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

	  <PropertyGroup>
        <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
        <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
    </PropertyGroup>

	  <ItemGroup>
	    <PackageReference Include="Hsu.Sg.FluentMember" Version="2024.101.8-rc175707">
	      <PrivateAssets>all</PrivateAssets>
	      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
	    </PackageReference>
	  </ItemGroup>

	 
	  
</Project>


The code that you will use is


using Builder;

var pOld = new Person();
pOld= pOld.WithFirstName("Andrei").WithLastName("Ignat").WithMiddleName("G");

System.Console.WriteLine(pOld.FullName());



namespace Builder;
[Hsu.Sg.FluentMember.FluentMember]
public partial class Person
{
    public string FirstName { get; init; }
    public string? MiddleName { get; init; }
    public string LastName { get; init; }

    public string FullName()
    {
        return FirstName + " " + MiddleName + " "+LastName;
    }
    
}


 

The code that is generated is

// <auto-generated/>

using System;

namespace Hsu.Sg.FluentMember
{
    /// <summary>
    /// The flag to generate member set method.
    /// </summary>
    [AttributeUsage(
        AttributeTargets.Struct |
        AttributeTargets.Class,
        AllowMultiple = false,
        Inherited = false)]
    internal sealed class FluentMemberAttribute : Attribute
    {
        
        /// <summary>
        ///     The public member are generated.
        /// </summary>
        public bool Public { get; set; } = true;

        /// <summary>
        ///     The internal member are generated.
        /// </summary>
        public bool Internal { get; set; }

        /// <summary>
        ///     The private member are generated.
        /// </summary>
        public bool Private { get; set; }

        /// <summary>
        ///     Only [FluentMemberGen] member are generated.
        /// </summary>
        public bool Only { get; set; }

        /// <summary>
        /// The prefix of member name.
        /// </summary>
        /// <remarks>default is `With`</remarks>
        public string Prefix { get; set; } = string.Empty;
    }

    [AttributeUsage(AttributeTargets.Field |
        AttributeTargets.Property |
        AttributeTargets.Event,
        AllowMultiple = false,
        Inherited = false)]
    internal sealed class FluentMemberGenAttribute : Attribute
    {
        /// <summary>
        ///   Ignore member.
        /// </summary>
        public bool Ignore { get; set; }

        /// <summary>
        /// The specific name of member.
        /// </summary>
        public string Identifier { get; set; } = string.Empty;

        /// <summary>
        /// The prefix of member name.
        /// </summary>
        /// <remarks>default is `With`</remarks>
        public string Prefix { get; set; } = string.Empty;

        /// <summary>
        /// The modifier of member
        /// </summary>
        /// <remarks>default is <see cref="Accessibility.Inherit"/></remarks>
        public Accessibility Modifier { get; set; } = Accessibility.Inherit;
    }

    /// <summary>
    /// The accessibility for fluent member set method.
    /// </summary>
    //[System.DefaultValue(Inherit)]
    internal enum Accessibility
    {
        /// <summary>
        /// Inherit from the member.
        /// </summary>
        Inherit,
        /// <summary>
        /// Is public access.
        /// </summary>
        Public,
        /// <summary>
        /// Is internal access.
        /// </summary>
        Internal,
        /// <summary>
        /// Is protected access.
        /// </summary>
        Protected,
        /// <summary>
        /// Is private access.
        /// </summary>
        Private
    }
    
    /// <summary>
    /// The event assignment
    /// </summary>
    //[System.DefaultValue(Add)]
    public enum EventAssignable
    {
        /// <summary>
        /// To add the event
        /// </summary>
        Add,
        /// <summary>
        /// To remove the event
        /// </summary>
        Remove,
        /// <summary>
        /// To set the event
        /// </summary>
        Assign
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Hsu.Sg.FluentMember

RSCG – QueryStringGenerator

RSCG – QueryStringGenerator
 
 

name QueryStringGenerator
nuget https://www.nuget.org/packages/QueryStringGenerator/
link https://github.com/tparviainen/query-string-generator
author Tomi Parviainen

Generate from string properties of a class a query string for a URL.

 

This is how you can use QueryStringGenerator .

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="QueryStringGenerator" Version="1.1.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


using DemoQuery;
Person p = new();
p.FirstName = "Andrei";
p.LastName = "Ignat";
p.Age = 55;
Console.WriteLine(p.ToQueryString());


using QueryStringGenerator;
namespace DemoQuery;
[QueryString]
internal class Person
{
    public string FirstName { get; set; }=string.Empty;
    public int Age {  get; set; }
    public string LastName { get; set; } = string.Empty;

}


 

The code that is generated is

// <auto-generated />

namespace DemoQuery
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("QueryStringGenerator", "1.0.0")]
    internal static class QueryStringExtensionForPerson
    {
        public static string ToQueryString(this Person _this)
        {
            if (_this == null)
            {
                return string.Empty;
            }

            var sb = new System.Text.StringBuilder();

            if (_this.FirstName != null)
            {
                sb.Append($"&firstname={System.Net.WebUtility.UrlEncode(_this.FirstName)}");
            }

            if (_this.LastName != null)
            {
                sb.Append($"&lastname={System.Net.WebUtility.UrlEncode(_this.LastName)}");
            }

            return sb.ToString();
        }
    }
}

// <auto-generated />

namespace QueryStringGenerator
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("QueryStringGenerator", "1.0.0")]
    internal class QueryStringAttribute : System.Attribute
    {
        public string MethodName { get; set; }

        public QueryStringAttribute(string methodName = "ToQueryString")
        {
            MethodName = methodName;
        }
    }
}

Code and pdf at

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

RSCG – GenPack

RSCG – GenPack
 
 

name GenPack
nuget https://www.nuget.org/packages/GenPack/
link https://github.com/dimohy/GenPack
author dimohy

Generating Binary Serialization and properties for class

 

This is how you can use GenPack .

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="GenPack" Version=" 0.9.0-preview1" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
	</ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


using SerializerDemo;

var p= new Person() { Name= "Andrei Ignat" };
var bytes= p.ToPacket();
var entity = Person.FromPacket(bytes);
Console.WriteLine("name is "+entity.Name);



using GenPack;

namespace SerializerDemo;


[GenPackable]
public partial record Person
{

    public readonly static PacketSchema Schema = PacketSchemaBuilder.Create()
           .@short("Id", "Age description")
           .@string("Name", "Name description")
           .Build();
}



 

The code that is generated is

#pragma warning disable CS0219
namespace SerializerDemo
{
    public partial record Person : GenPack.IGenPackable
    {
        /// <summary>
        /// Age description
        /// </summary>
        public short Id { get; set; }
        /// <summary>
        /// Name description
        /// </summary>
        public string Name { get; set; } = string.Empty;
        public byte[] ToPacket()
        {
            using var ms = new System.IO.MemoryStream();
            ToPacket(ms);
            return ms.ToArray();
        }
        public void ToPacket(System.IO.Stream stream)
        {
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
            writer.Write(Id);
            writer.Write(Name);
        }
        public static SerializerDemo.Person FromPacket(byte[] data)
        {
            using var ms = new System.IO.MemoryStream(data);
            return FromPacket(ms);
        }
        public static SerializerDemo.Person FromPacket(System.IO.Stream stream)
        {
            SerializerDemo.Person result = new SerializerDemo.Person();
            System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
            int size = 0;
            byte[] buffer = null;
            result.Id = reader.ReadInt16();
            result.Name = reader.ReadString();
            return result;
        }
    }
}

Code and pdf at

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

RSCG – Credfeto.Version.Information.Generator

RSCG – Credfeto.Version.Information.Generator
 
 

name Credfeto.Version.Information.Generator
nuget https://www.nuget.org/packages/Credfeto.Version.Information.Generator/
link https://github.com/credfeto/credfeto-version-constants-generator
author Mark Ridgwell

Embedding build information as compile time constants in C# projects.

 

This is how you can use Credfeto.Version.Information.Generator .

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>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
	<PropertyGroup>
		<!-- this is the code to start RSCG -->
		<Version>2024.11.15.450</Version>

		<Company>AOM</Company>
		<Copyright>MIT</Copyright>
		<Product>Info Test</Product>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Credfeto.Version.Information.Generator" Version="1.0.2.16" PrivateAssets="All"
						  ExcludeAssets="runtime"/>
	</ItemGroup>

</Project>


The code that you will use is


Console.WriteLine(Info.VersionInformation.Version);
Console.WriteLine(Info.VersionInformation.Product);


 

The code that is generated is

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version: Current
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.CodeDom.Compiler;

namespace Info;

[GeneratedCode(tool: "Credfeto.Version.Information.Generator", version: "1.0.2.16")]
internal static class VersionInformation
{
    public const string Version = "2024.11.15.450";
    public const string Product = "Info";
    public const string Company = "AOM";
    public const string Copyright = "MIT";
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Credfeto.Version.Information.Generator

RSCG – polytype

RSCG – polytype
 
 

name polytype
nuget https://www.nuget.org/packages/polytype/
link https://github.com/eiriktsarpalis/PolyType
author Eirik Tsarpalis

Generating shape like reflection from classes. See PolyType.Examples for more details

 

This is how you can use polytype .

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="PolyType" Version="0.16.1" />
    <PackageReference Include="PolyType.Examples" Version="0.16.1" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


using PolyType.Examples.JsonSerializer;
using PolyType.Examples.CborSerializer;
using PolyType.Examples.XmlSerializer;
using ConsoleApp1;
using PolyType.Examples.Cloner;

Person person = new("Pete", 70);
Console.WriteLine(JsonSerializerTS.Serialize(person)); // {"Name":"Pete","Age":70}
Console.WriteLine(XmlSerializer.Serialize(person));    // <value><Name>Pete</Name><Age>70</Age></value>
Console.WriteLine(CborSerializer.EncodeToHex(person)); // A2644E616D656450657465634167651846
person.Childs = [new Person("Andrei", 55)];

person.Childs[0].ID = 1;
var q = Cloner.Clone(person);
person.Childs[0].ID = 10;
Console.WriteLine(q);
Console.WriteLine(person);
Console.WriteLine(q.Childs[0]);
Console.WriteLine(person.Childs[0]);



using PolyType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1;
[GenerateShape]
public partial record Person(string name, int age)
{
    public Person[] Childs { get; set; } = [];

    public int ID;
}

 

The code that is generated is

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace ConsoleApp1
{
    public partial record Person : global::PolyType.IShapeable<global::ConsoleApp1.Person>
    {
        static global::PolyType.Abstractions.ITypeShape<global::ConsoleApp1.Person> global::PolyType.IShapeable<global::ConsoleApp1.Person>.GetShape() 
            => global::PolyType.SourceGenerator.GenerateShapeProvider.Default.Person;
    }
}

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace PolyType.SourceGenerator
{
    internal partial class GenerateShapeProvider
    {
        private const global::System.Reflection.BindingFlags InstanceBindingFlags = 
            global::System.Reflection.BindingFlags.Public | 
            global::System.Reflection.BindingFlags.NonPublic | 
            global::System.Reflection.BindingFlags.Instance;
        
        /// <summary>Gets the default instance of the <see cref="GenerateShapeProvider"/> class.</summary>
        public static GenerateShapeProvider Default { get; } = new();
        
        /// <summary>Initializes a new instance of the <see cref="GenerateShapeProvider"/> class.</summary>
        public GenerateShapeProvider() { }
    }
}

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace PolyType.SourceGenerator
{
    internal partial class GenerateShapeProvider
    {
        /// <summary>Gets the generated shape for specified type.</summary>
#nullable disable annotations // Use nullable-oblivious property type
        public global::PolyType.Abstractions.ITypeShape<int> Int32 => _Int32 ??= Create_Int32();
#nullable enable annotations // Use nullable-oblivious property type
        private global::PolyType.Abstractions.ITypeShape<int>? _Int32;

        private global::PolyType.Abstractions.ITypeShape<int> Create_Int32()
        {
            return new global::PolyType.SourceGenModel.SourceGenObjectTypeShape<int>
            {
                Provider = this,
                IsRecordType = false,
                IsTupleType = false,
                CreatePropertiesFunc = null,
                CreateConstructorFunc = null,
            };
        }
    }
}

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace PolyType.SourceGenerator
{
    internal partial class GenerateShapeProvider : global::PolyType.ITypeShapeProvider
    {
        /// <summary>
        /// Gets the generated <see cref="global::PolyType.Abstractions.ITypeShape{T}" /> for the specified type.
        /// </summary>
        /// <typeparam name="T">The type for which a shape is requested.</typeparam>
        /// <returns>
        /// The generated <see cref="global::PolyType.Abstractions.ITypeShape{T}" /> for the specified type.
        /// </returns>
        public global::PolyType.Abstractions.ITypeShape<T>? GetShape<T>()
            => (global::PolyType.Abstractions.ITypeShape<T>?)GetShape(typeof(T));
        
        /// <summary>
        /// Gets the generated <see cref="global::PolyType.Abstractions.ITypeShape" /> for the specified type.
        /// </summary>
        /// <param name="type">The type for which a shape is requested.</param>
        /// <returns>
        /// The generated <see cref="global::PolyType.Abstractions.ITypeShape" /> for the specified type.
        /// </returns>
        public global::PolyType.Abstractions.ITypeShape? GetShape(global::System.Type type)
        {
            if (type == typeof(global::ConsoleApp1.Person[]))
                return Person_Array;
            
            if (type == typeof(string))
                return String;
            
            if (type == typeof(global::ConsoleApp1.Person))
                return Person;
            
            if (type == typeof(int))
                return Int32;
            
            return null;
        }
    }
}

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace PolyType.SourceGenerator
{
    internal partial class GenerateShapeProvider
    {
        /// <summary>Gets the generated shape for specified type.</summary>
#nullable disable annotations // Use nullable-oblivious property type
        public global::PolyType.Abstractions.ITypeShape<global::ConsoleApp1.Person> Person => _Person ??= Create_Person();
#nullable enable annotations // Use nullable-oblivious property type
        private global::PolyType.Abstractions.ITypeShape<global::ConsoleApp1.Person>? _Person;

        private global::PolyType.Abstractions.ITypeShape<global::ConsoleApp1.Person> Create_Person()
        {
            return new global::PolyType.SourceGenModel.SourceGenObjectTypeShape<global::ConsoleApp1.Person>
            {
                Provider = this,
                IsRecordType = true,
                IsTupleType = false,
                CreatePropertiesFunc = CreateProperties_Person,
                CreateConstructorFunc = CreateConstructor_Person,
            };
        }

        private global::PolyType.Abstractions.IPropertyShape[] CreateProperties_Person() => new global::PolyType.Abstractions.IPropertyShape[]
        {
            new global::PolyType.SourceGenModel.SourceGenPropertyShape<global::ConsoleApp1.Person, string>
            {
                Name = "name",
                DeclaringType = (global::PolyType.Abstractions.IObjectTypeShape<global::ConsoleApp1.Person>)Person,
                PropertyType = String,
                Getter = static (ref global::ConsoleApp1.Person obj) => obj.name,
                Setter = null,
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetProperty("name", InstanceBindingFlags, null, typeof(string), [], null),
                IsField = false,
                IsGetterPublic = true,
                IsSetterPublic = false,
                IsGetterNonNullable = true,
                IsSetterNonNullable = false,
            },

            new global::PolyType.SourceGenModel.SourceGenPropertyShape<global::ConsoleApp1.Person, int>
            {
                Name = "age",
                DeclaringType = (global::PolyType.Abstractions.IObjectTypeShape<global::ConsoleApp1.Person>)Person,
                PropertyType = Int32,
                Getter = static (ref global::ConsoleApp1.Person obj) => obj.age,
                Setter = null,
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetProperty("age", InstanceBindingFlags, null, typeof(int), [], null),
                IsField = false,
                IsGetterPublic = true,
                IsSetterPublic = false,
                IsGetterNonNullable = true,
                IsSetterNonNullable = false,
            },

            new global::PolyType.SourceGenModel.SourceGenPropertyShape<global::ConsoleApp1.Person, global::ConsoleApp1.Person[]>
            {
                Name = "Childs",
                DeclaringType = (global::PolyType.Abstractions.IObjectTypeShape<global::ConsoleApp1.Person>)Person,
                PropertyType = Person_Array,
                Getter = static (ref global::ConsoleApp1.Person obj) => obj.Childs,
                Setter = static (ref global::ConsoleApp1.Person obj, global::ConsoleApp1.Person[] value) => obj.Childs = value,
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetProperty("Childs", InstanceBindingFlags, null, typeof(global::ConsoleApp1.Person[]), [], null),
                IsField = false,
                IsGetterPublic = true,
                IsSetterPublic = true,
                IsGetterNonNullable = true,
                IsSetterNonNullable = true,
            },

            new global::PolyType.SourceGenModel.SourceGenPropertyShape<global::ConsoleApp1.Person, int>
            {
                Name = "ID",
                DeclaringType = (global::PolyType.Abstractions.IObjectTypeShape<global::ConsoleApp1.Person>)Person,
                PropertyType = Int32,
                Getter = static (ref global::ConsoleApp1.Person obj) => obj.ID,
                Setter = static (ref global::ConsoleApp1.Person obj, int value) => obj.ID = value,
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetField("ID", InstanceBindingFlags),
                IsField = true,
                IsGetterPublic = true,
                IsSetterPublic = true,
                IsGetterNonNullable = true,
                IsSetterNonNullable = true,
            },
        };

        private global::PolyType.Abstractions.IConstructorShape CreateConstructor_Person()
        {
            return new global::PolyType.SourceGenModel.SourceGenConstructorShape<global::ConsoleApp1.Person, (string, int, global::ConsoleApp1.Person[], int, byte Flags)>
            {
                DeclaringType = (global::PolyType.Abstractions.IObjectTypeShape<global::ConsoleApp1.Person>)Person,
                ParameterCount = 4,
                GetParametersFunc = CreateConstructorParameters_Person,
                DefaultConstructorFunc = null,
                ArgumentStateConstructorFunc = static () => default((string, int, global::ConsoleApp1.Person[], int, byte Flags)),
                ParameterizedConstructorFunc = static (ref (string, int, global::ConsoleApp1.Person[], int, byte Flags) state) => { var obj = new global::ConsoleApp1.Person(state.Item1, state.Item2);  if ((state.Flags & 1) != 0) obj.Childs = state.Item3; if ((state.Flags & 2) != 0) obj.ID = state.Item4; return obj; },
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetConstructor(InstanceBindingFlags, new[] { typeof(string), typeof(int) }),
                IsPublic = true,
            };
        }

        private global::PolyType.Abstractions.IConstructorParameterShape[] CreateConstructorParameters_Person() => new global::PolyType.Abstractions.IConstructorParameterShape[]
        {
            new global::PolyType.SourceGenModel.SourceGenConstructorParameterShape<(string, int, global::ConsoleApp1.Person[], int, byte Flags), string>
            {
                Position = 0,
                Name = "name",
                ParameterType = String,
                Kind = global::PolyType.Abstractions.ConstructorParameterKind.ConstructorParameter,
                IsRequired = true,
                IsNonNullable = true,
                IsPublic = true,
                HasDefaultValue = false,
                DefaultValue = default!,
                Setter = static (ref (string, int, global::ConsoleApp1.Person[], int, byte Flags) state, string value) => state.Item1 = value,
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetConstructor(InstanceBindingFlags, new[] { typeof(string), typeof(int) })?.GetParameters()[0],
            },

            new global::PolyType.SourceGenModel.SourceGenConstructorParameterShape<(string, int, global::ConsoleApp1.Person[], int, byte Flags), int>
            {
                Position = 1,
                Name = "age",
                ParameterType = Int32,
                Kind = global::PolyType.Abstractions.ConstructorParameterKind.ConstructorParameter,
                IsRequired = true,
                IsNonNullable = true,
                IsPublic = true,
                HasDefaultValue = false,
                DefaultValue = default,
                Setter = static (ref (string, int, global::ConsoleApp1.Person[], int, byte Flags) state, int value) => state.Item2 = value,
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetConstructor(InstanceBindingFlags, new[] { typeof(string), typeof(int) })?.GetParameters()[1],
            },

            new global::PolyType.SourceGenModel.SourceGenConstructorParameterShape<(string, int, global::ConsoleApp1.Person[], int, byte Flags), global::ConsoleApp1.Person[]>
            {
                Position = 2,
                Name = "Childs",
                ParameterType = Person_Array,
                Kind = global::PolyType.Abstractions.ConstructorParameterKind.PropertyInitializer,
                IsRequired = false,
                IsNonNullable = true,
                IsPublic = true,
                HasDefaultValue = false,
                DefaultValue = default!,
                Setter = static (ref (string, int, global::ConsoleApp1.Person[], int, byte Flags) state, global::ConsoleApp1.Person[] value) => { state.Item3 = value; state.Flags |= 1; },
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetProperty("Childs", InstanceBindingFlags, null, typeof(global::ConsoleApp1.Person[]), [], null),
            },

            new global::PolyType.SourceGenModel.SourceGenConstructorParameterShape<(string, int, global::ConsoleApp1.Person[], int, byte Flags), int>
            {
                Position = 3,
                Name = "ID",
                ParameterType = Int32,
                Kind = global::PolyType.Abstractions.ConstructorParameterKind.FieldInitializer,
                IsRequired = false,
                IsNonNullable = true,
                IsPublic = true,
                HasDefaultValue = false,
                DefaultValue = default,
                Setter = static (ref (string, int, global::ConsoleApp1.Person[], int, byte Flags) state, int value) => { state.Item4 = value; state.Flags |= 2; },
                AttributeProviderFunc = static () => typeof(global::ConsoleApp1.Person).GetField("ID", InstanceBindingFlags),
            },
        };

        [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "set_name")]
        private static extern void Person_name_SetAccessor(global::ConsoleApp1.Person obj, string value);

        [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "set_age")]
        private static extern void Person_age_SetAccessor(global::ConsoleApp1.Person obj, int value);

        [global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Field, Name = "ID")]
        private static extern ref int Person_ID_Accessor(global::ConsoleApp1.Person obj);
    }
}

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace PolyType.SourceGenerator
{
    internal partial class GenerateShapeProvider
    {
        /// <summary>Gets the generated shape for specified type.</summary>
#nullable disable annotations // Use nullable-oblivious property type
        public global::PolyType.Abstractions.ITypeShape<global::ConsoleApp1.Person[]> Person_Array => _Person_Array ??= Create_Person_Array();
#nullable enable annotations // Use nullable-oblivious property type
        private global::PolyType.Abstractions.ITypeShape<global::ConsoleApp1.Person[]>? _Person_Array;

        private global::PolyType.Abstractions.ITypeShape<global::ConsoleApp1.Person[]> Create_Person_Array()
        {
            return new global::PolyType.SourceGenModel.SourceGenEnumerableTypeShape<global::ConsoleApp1.Person[], global::ConsoleApp1.Person>
            {
                ElementType = Person,
                ConstructionStrategy = global::PolyType.Abstractions.CollectionConstructionStrategy.Span,
                DefaultConstructorFunc = null,
                EnumerableConstructorFunc = null,
                SpanConstructorFunc = static values => values.ToArray(),
                GetEnumerableFunc = static obj => obj,
                AddElementFunc = null,
                Rank = 1,
                Provider = this,
           };
        }
    }
}

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

namespace PolyType.SourceGenerator
{
    internal partial class GenerateShapeProvider
    {
        /// <summary>Gets the generated shape for specified type.</summary>
#nullable disable annotations // Use nullable-oblivious property type
        public global::PolyType.Abstractions.ITypeShape<string> String => _String ??= Create_String();
#nullable enable annotations // Use nullable-oblivious property type
        private global::PolyType.Abstractions.ITypeShape<string>? _String;

        private global::PolyType.Abstractions.ITypeShape<string> Create_String()
        {
            return new global::PolyType.SourceGenModel.SourceGenObjectTypeShape<string>
            {
                Provider = this,
                IsRecordType = false,
                IsTupleType = false,
                CreatePropertiesFunc = null,
                CreateConstructorFunc = null,
            };
        }
    }
}

Code and pdf at

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

RSCG – Datacute.EmbeddedResourcePropertyGenerator

RSCG – Datacute.EmbeddedResourcePropertyGenerator
 
 

name Datacute.EmbeddedResourcePropertyGenerator
nuget https://www.nuget.org/packages/Datacute.EmbeddedResourcePropertyGenerator/
link https://github.com/datacute/EmbeddedResourcePropertyGenerator/
author Stephen Denne

Generating class to access easy the embedded resource

 

This is how you can use Datacute.EmbeddedResourcePropertyGenerator .

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>
    <EmbeddedResource Include="TestData\Countries.txt" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Datacute.EmbeddedResourcePropertyGenerator" Version="1.0.0" >
    </PackageReference>
  </ItemGroup>
	<PropertyGroup>
		<AdditionalFileItemNames>$(AdditionalFileItemNames);EmbeddedResource</AdditionalFileItemNames>
	</PropertyGroup>
	<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 EmbedDemo;

Console.WriteLine("Hello, World!");

var data= TestData.Countries;

Console.WriteLine(data);


using Datacute.EmbeddedResourcePropertyGenerator;
namespace EmbedDemo;
[EmbeddedResourceProperties(".txt", "TestData")]
public static partial class TestData;



USA
Germany
France
Romania
Italy


 

The code that is generated is

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by the Datacute.EmbeddedResourcePropertyGenerator.
// </auto-generated>
//------------------------------------------------------------------------------

#nullable enable

namespace EmbedDemo;
/// <summary>
/// This class's properties are generated from project files meeting the criteria:
/// <list type="bullet">
/// <item>
/// <description>they are both an <c>EmbeddedResource</c> and an <c>AdditionalFile</c></description>
/// </item>
/// <item>
/// <description>they are in the project folder <c>TestData</c></description>
/// </item>
/// <item>
/// <description>they have the extension <c>.txt</c></description>
/// </item>
/// </list>
/// </summary>
public static partial class TestData
{
    private static class EmbeddedResource
    {
        public static string Read(string resourceName)
        {
            var assembly = typeof(TestData).Assembly;
            using var stream = assembly.GetManifestResourceStream(resourceName)!;
            using var streamReader = new global::System.IO.StreamReader(stream, global::System.Text.Encoding.UTF8);
            var resourceText = streamReader.ReadToEnd();
            return resourceText;
        }
        public static class BackingField
        {
            public static string? Countries;
        }
        public static class ResourceName
        {
            public const string Countries = "EmbedDemo.TestData.Countries.txt";
        }
    }
    static partial void ReadEmbeddedResourceValue(ref string? backingField, string resourceName, string propertyName);
    static partial void AlterEmbeddedResourceReturnValue(ref string value, string resourceName, string propertyName);

    /// <summary>Text value of the Embedded Resource: Countries.txt</summary>
    /// <value>
    /// <code>
    /// USA
    /// Germany
    /// France
    /// Romania
    /// Italy
    /// 
    /// </code>
    /// </value>
    /// <remarks>
    /// The value is read from the embedded resource on first access.
    /// </remarks>
    public static string Countries
    {
        get
        {
            ReadEmbeddedResourceValue(ref EmbeddedResource.BackingField.Countries, EmbeddedResource.ResourceName.Countries, "Countries");
            var value = EmbeddedResource.BackingField.Countries ??= EmbeddedResource.Read(EmbeddedResource.ResourceName.Countries);
            AlterEmbeddedResourceReturnValue(ref value, EmbeddedResource.ResourceName.Countries, "Countries");
            return value;
        }
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Datacute.EmbeddedResourcePropertyGenerator

RSCG – rscg_queryables

RSCG – rscg_queryables
 
 

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

Generating code for .Where and .OrderBy by string, not by lambda

 

This is how you can use rscg_queryables .

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_queryablesCommon" Version="2024.1110.1815" />
		<PackageReference Include="rscg_queryables" Version="2024.1110.1815"  OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
	</ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


using SortAndWhere;


Console.WriteLine("Hello, World!");

var students = new Student[]
{
    new Student { FirstName = "John", LastName = "Doe", StartYear = 1935},
    new Student { FirstName = "Ignat", LastName = "Andrei", StartYear = 1989 },
};

var orderedExplicitly = students.OrderBy(p => p.FirstName).ToArray();
var orderedImplicitly = students.OrderBy("firStnaMe").ToArray();
var orderedImplicitly2 = students.AsQueryable().OrderBy("fIrsTnAme").ToArray();


//Search by property name

var search = students.AsQueryable().Where("firstName", rscg_queryablesCommon.WhereOperator.Equal, "John").ToArray();

Console.WriteLine("found : " + search.Length);

search = students.AsQueryable().Where(Student_.Where_Expr("firstName", rscg_queryablesCommon.WhereOperator.Equal, "John")).ToArray();
Console.WriteLine("found : " + search.Length);





using rscg_queryablesCommon;

namespace SortAndWhere;
[MakeSortable]
[MakeWhere]
public class Student
{
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;

    public int StartYear { get; set; }

}


 

The code that is generated is


public static partial class ExtensionsSortable_SortAndWhere_Student {
    
    #region Enumerable
    public static System.Linq.IOrderedEnumerable<global::SortAndWhere.Student> OrderBy
    (
    this IEnumerable<global::SortAndWhere.Student>
        source, string propertyName
    )
    {

        return OrderByAscDesc(source,propertyName,true);
    }
        public static System.Linq.IOrderedEnumerable<global::SortAndWhere.Student>
            OrderByDescending
            (
            this IEnumerable<global::SortAndWhere.Student>
                source, string propertyName
                )
                {

                return OrderByAscDesc(source,propertyName,false);
                }
    public static System.Linq.IOrderedEnumerable<global::SortAndWhere.Student> OrderByAscDesc
    (
     this IEnumerable<global::SortAndWhere.Student> source, string propertyName, bool Ascending
    )
   {

                        if(string.Equals(propertyName, "FirstName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.OrderBy(x => x.FirstName);
                            else
                                return source.OrderByDescending(x => x.FirstName);                            
                        }
                    
                        if(string.Equals(propertyName, "LastName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.OrderBy(x => x.LastName);
                            else
                                return source.OrderByDescending(x => x.LastName);                            
                        }
                    
                        if(string.Equals(propertyName, "StartYear", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.OrderBy(x => x.StartYear);
                            else
                                return source.OrderByDescending(x => x.StartYear);                            
                        }
                                    throw new ArgumentException($"Property {propertyName} not found", propertyName);
    }

    public static System.Linq.IOrderedEnumerable<global::SortAndWhere.Student> ThenByAscDesc
    (
     this IOrderedEnumerable<global::SortAndWhere.Student> source, string propertyName, bool Ascending
    )
   {

                        if(string.Equals(propertyName, "FirstName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.ThenBy(x => x.FirstName);
                            else
                                return source.ThenByDescending(x => x.FirstName);                            
                        }
                    
                        if(string.Equals(propertyName, "LastName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.ThenBy(x => x.LastName);
                            else
                                return source.ThenByDescending(x => x.LastName);                            
                        }
                    
                        if(string.Equals(propertyName, "StartYear", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.ThenBy(x => x.StartYear);
                            else
                                return source.ThenByDescending(x => x.StartYear);                            
                        }
                                    throw new ArgumentException($"Property {propertyName} not found", propertyName);
    }
    public static System.Linq.IOrderedEnumerable<global::SortAndWhere.Student> ThenBy
    (
    this IOrderedEnumerable<global::SortAndWhere.Student>
        source, string propertyName
    )
    {

        return ThenByAscDesc(source,propertyName,true);
    }
    public static System.Linq.IOrderedEnumerable<global::SortAndWhere.Student> ThenByDescending
    (
    this IOrderedEnumerable<global::SortAndWhere.Student>
        source, string propertyName
    )
    {

        return ThenByAscDesc(source,propertyName,false);
    }

    #endregion 

#region Queryable
    public static System.Linq.IOrderedQueryable<global::SortAndWhere.Student> OrderBy
    (
    this IQueryable<global::SortAndWhere.Student>
        source, string propertyName
    )
    {

        return OrderByAscDesc(source,propertyName,true);
    }
        public static System.Linq.IOrderedQueryable<global::SortAndWhere.Student>
            OrderByDescending
            (
            this IQueryable<global::SortAndWhere.Student>
                source, string propertyName
                )
                {

                return OrderByAscDesc(source,propertyName,false);
                }
    public static System.Linq.IOrderedQueryable<global::SortAndWhere.Student> OrderByAscDesc
    (
     this IQueryable<global::SortAndWhere.Student> source, string propertyName, bool Ascending
    )
   {

                        if(string.Equals(propertyName, "FirstName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.OrderBy(x => x.FirstName);
                            else
                                return source.OrderByDescending(x => x.FirstName);                            
                        }
                    
                        if(string.Equals(propertyName, "LastName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.OrderBy(x => x.LastName);
                            else
                                return source.OrderByDescending(x => x.LastName);                            
                        }
                    
                        if(string.Equals(propertyName, "StartYear", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.OrderBy(x => x.StartYear);
                            else
                                return source.OrderByDescending(x => x.StartYear);                            
                        }
                                    throw new ArgumentException($"Property {propertyName} not found", propertyName);
    }
    public static System.Linq.IOrderedQueryable<global::SortAndWhere.Student> ThenByAscDesc
    (
     this IOrderedQueryable<global::SortAndWhere.Student> source, string propertyName, bool Ascending
    )
   {

                        if(string.Equals(propertyName, "FirstName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.ThenBy(x => x.FirstName);
                            else
                                return source.ThenByDescending(x => x.FirstName);                            
                        }
                    
                        if(string.Equals(propertyName, "LastName", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.ThenBy(x => x.LastName);
                            else
                                return source.ThenByDescending(x => x.LastName);                            
                        }
                    
                        if(string.Equals(propertyName, "StartYear", StringComparison.OrdinalIgnoreCase)){
                            if(Ascending)
                                return source.ThenBy(x => x.StartYear);
                            else
                                return source.ThenByDescending(x => x.StartYear);                            
                        }
                                    throw new ArgumentException($"Property {propertyName} not found", propertyName);
    }
    public static System.Linq.IOrderedQueryable<global::SortAndWhere.Student> ThenBy
    (
    this IOrderedQueryable<global::SortAndWhere.Student>
        source, string propertyName
    )
    {

        return ThenByAscDesc(source,propertyName,true);
    }
    public static System.Linq.IOrderedQueryable<global::SortAndWhere.Student> ThenByDescending
    (
    this IOrderedQueryable<global::SortAndWhere.Student>
        source, string propertyName
    )
    {

        return ThenByAscDesc(source,propertyName,false);
    }

    #endregion 

}

public static class ExtensionsWhere_SortAndWhere_Student{
    

        internal static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        FirstName_Expr_Equal(string argument) => (a => a.FirstName== argument);

        internal static Func<global::SortAndWhere.Student,bool>
            FirstName_Equal(string argument) => (a => a.FirstName== argument);

        internal static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        FirstName_Expr_NotEqual(string argument) => (a => a.FirstName != argument);

        internal static Func<global::SortAndWhere.Student,bool>
                FirstName_NotEqual(string argument) => (a => a.FirstName != argument);

    
        internal static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        LastName_Expr_Equal(string argument) => (a => a.LastName== argument);

        internal static Func<global::SortAndWhere.Student,bool>
            LastName_Equal(string argument) => (a => a.LastName== argument);

        internal static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        LastName_Expr_NotEqual(string argument) => (a => a.LastName != argument);

        internal static Func<global::SortAndWhere.Student,bool>
                LastName_NotEqual(string argument) => (a => a.LastName != argument);

    
        internal static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        StartYear_Expr_Equal(int argument) => (a => a.StartYear== argument);

        internal static Func<global::SortAndWhere.Student,bool>
            StartYear_Equal(int argument) => (a => a.StartYear== argument);

        internal static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        StartYear_Expr_NotEqual(int argument) => (a => a.StartYear != argument);

        internal static Func<global::SortAndWhere.Student,bool>
                StartYear_NotEqual(int argument) => (a => a.StartYear != argument);

    
   

}
public static class Student_{


        public static System.Linq.IQueryable<global::SortAndWhere.Student>
            Where(this System.Linq.IQueryable<global::SortAndWhere.Student> original,
                string propertyName,rscg_queryablesCommon.WhereOperator operatorWhere, string argument)
        {
            return original.Where(Where_Expr(propertyName, operatorWhere, argument));
        }
        public static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        Where_Expr(string propertyName,rscg_queryablesCommon.WhereOperator operatorWhere, string argument)
            {

                    if(string.Equals(propertyName,  "FirstName", StringComparison.OrdinalIgnoreCase)){
                    switch(operatorWhere){
                    case rscg_queryablesCommon.WhereOperator.Equal:
                    return ExtensionsWhere_SortAndWhere_Student.FirstName_Expr_Equal( argument);
                    case rscg_queryablesCommon.WhereOperator.NotEqual:
                    return ExtensionsWhere_SortAndWhere_Student.FirstName_Expr_NotEqual( argument);
                    default:
                    throw new ArgumentException($"Operator {operatorWhere} not found");
                    }//end switch
                    }//end if FirstName

                
                    if(string.Equals(propertyName,  "LastName", StringComparison.OrdinalIgnoreCase)){
                    switch(operatorWhere){
                    case rscg_queryablesCommon.WhereOperator.Equal:
                    return ExtensionsWhere_SortAndWhere_Student.LastName_Expr_Equal( argument);
                    case rscg_queryablesCommon.WhereOperator.NotEqual:
                    return ExtensionsWhere_SortAndWhere_Student.LastName_Expr_NotEqual( argument);
                    default:
                    throw new ArgumentException($"Operator {operatorWhere} not found");
                    }//end switch
                    }//end if LastName

                
            throw new ArgumentException("Property "+ propertyName +" not found for string type");
            }





        public static Func<global::SortAndWhere.Student,bool>
            Where(string propertyName,rscg_queryablesCommon.WhereOperator operatorWhere, string argument)
            {

                    if(string.Equals(propertyName,  "FirstName", StringComparison.OrdinalIgnoreCase)){
                    switch(operatorWhere){
                    case rscg_queryablesCommon.WhereOperator.Equal:
                    return ExtensionsWhere_SortAndWhere_Student.FirstName_Equal( argument);
                    case rscg_queryablesCommon.WhereOperator.NotEqual:
                    return ExtensionsWhere_SortAndWhere_Student.FirstName_NotEqual( argument);
                    default:
                    throw new ArgumentException($"Operator {operatorWhere} not found");
                    }//end switch
                    }//end if FirstName

                
                    if(string.Equals(propertyName,  "LastName", StringComparison.OrdinalIgnoreCase)){
                    switch(operatorWhere){
                    case rscg_queryablesCommon.WhereOperator.Equal:
                    return ExtensionsWhere_SortAndWhere_Student.LastName_Equal( argument);
                    case rscg_queryablesCommon.WhereOperator.NotEqual:
                    return ExtensionsWhere_SortAndWhere_Student.LastName_NotEqual( argument);
                    default:
                    throw new ArgumentException($"Operator {operatorWhere} not found");
                    }//end switch
                    }//end if LastName

                
            throw new ArgumentException("Property "+ propertyName +" not found for string type");
            }

    
        public static System.Linq.IQueryable<global::SortAndWhere.Student>
            Where(this System.Linq.IQueryable<global::SortAndWhere.Student> original,
                string propertyName,rscg_queryablesCommon.WhereOperator operatorWhere, int argument)
        {
            return original.Where(Where_Expr(propertyName, operatorWhere, argument));
        }
        public static System.Linq.Expressions.Expression < Func < global::SortAndWhere.Student,bool>>
        Where_Expr(string propertyName,rscg_queryablesCommon.WhereOperator operatorWhere, int argument)
            {

                    if(string.Equals(propertyName,  "StartYear", StringComparison.OrdinalIgnoreCase)){
                    switch(operatorWhere){
                    case rscg_queryablesCommon.WhereOperator.Equal:
                    return ExtensionsWhere_SortAndWhere_Student.StartYear_Expr_Equal( argument);
                    case rscg_queryablesCommon.WhereOperator.NotEqual:
                    return ExtensionsWhere_SortAndWhere_Student.StartYear_Expr_NotEqual( argument);
                    default:
                    throw new ArgumentException($"Operator {operatorWhere} not found");
                    }//end switch
                    }//end if StartYear

                
            throw new ArgumentException("Property "+ propertyName +" not found for int type");
            }





        public static Func<global::SortAndWhere.Student,bool>
            Where(string propertyName,rscg_queryablesCommon.WhereOperator operatorWhere, int argument)
            {

                    if(string.Equals(propertyName,  "StartYear", StringComparison.OrdinalIgnoreCase)){
                    switch(operatorWhere){
                    case rscg_queryablesCommon.WhereOperator.Equal:
                    return ExtensionsWhere_SortAndWhere_Student.StartYear_Equal( argument);
                    case rscg_queryablesCommon.WhereOperator.NotEqual:
                    return ExtensionsWhere_SortAndWhere_Student.StartYear_NotEqual( argument);
                    default:
                    throw new ArgumentException($"Operator {operatorWhere} not found");
                    }//end switch
                    }//end if StartYear

                
            throw new ArgumentException("Property "+ propertyName +" not found for int type");
            }

    

}

Code and pdf at

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

RSCG – RazorSlices

RSCG – RazorSlices
 
 

name RazorSlices
nuget https://www.nuget.org/packages/RazorSlices/
link https://github.com/DamianEdwards/RazorSlices
author Damiam Edwards

Generating html from razor templates. Attention: generates IHttpResult, not html string.

 

This is how you can use RazorSlices .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
    <PackageReference Include="RazorSlices" Version="0.8.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
  </ItemGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


using RazorDemoSlices;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

var summaries = new[]
{
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/hello", (string firstName,string lastName) 
    => Results.Extensions.RazorSlice<RazorDemoSlices.Slices.PersonHTML, Person>(
        new Person { FirstName = firstName, LastName = lastName }
    ));

app.MapGet("/weatherforecast", () =>
{
    var forecast = Enumerable.Range(1, 5).Select(index =>
        new WeatherForecast
        (
            DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
            Random.Shared.Next(-20, 55),
            summaries[Random.Shared.Next(summaries.Length)]
        ))
        .ToArray();
    return forecast;
})
.WithName("GetWeatherForecast")
.WithOpenApi();

app.Run();

internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}



@inherits RazorSliceHttpResult<RazorDemoSlices.Person>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Hello from Razor Slices!</title>
</head>
<body>
    <p>
        My name is @Model.FirstName @Model.LastName
    </p>
</body>
</html>


namespace RazorDemoSlices;

public class Person
{
    public string FirstName { get; set; }=string.Empty;
    public string LastName { get; set; }= string.Empty;
}


 

The code that is generated is

#pragma checksum "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\PersonHTML.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6b3710e80836b438a5d8935ea469d238fc095e46298456ca847e09519393bb5e"
// <auto-generated/>
#pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCoreGeneratedDocument.Slices_PersonHTML), @"mvc.1.0.view", @"/Slices/PersonHTML.cshtml")]
namespace AspNetCoreGeneratedDocument
{
    #line default
    using global::System;
    using global::System.Collections.Generic;
    using global::System.Linq;
    using global::System.Threading.Tasks;
    using global::Microsoft.AspNetCore.Mvc;
    using global::Microsoft.AspNetCore.Mvc.Rendering;
    using global::Microsoft.AspNetCore.Mvc.ViewFeatures;
#nullable restore
#line (3,2)-(4,1) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\_ViewImports.cshtml"
using System.Globalization;

#nullable disable
#nullable restore
#line (4,2)-(5,1) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\_ViewImports.cshtml"
using Microsoft.AspNetCore.Razor;

#nullable disable
#nullable restore
#line (5,2)-(6,1) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\_ViewImports.cshtml"
using Microsoft.AspNetCore.Http.HttpResults;

#line default
#line hidden
#nullable disable
    [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/Slices/PersonHTML.cshtml")]
    [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute]
    #nullable restore
    internal sealed class Slices_PersonHTML : RazorSliceHttpResult<RazorDemoSlices.Person>
    #nullable disable
    {
        #pragma warning disable 1998
        public async override global::System.Threading.Tasks.Task ExecuteAsync()
        {
            WriteLiteral("<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n    <meta charset=\"utf-8\">\r\n    <title>Hello from Razor Slices!</title>\r\n</head>\r\n<body>\r\n    <p>\r\n        My name is ");
            Write(
#nullable restore
#line (10,21)-(10,36) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\PersonHTML.cshtml"
Model.FirstName

#line default
#line hidden
#nullable disable
            );
            WriteLiteral(" ");
            Write(
#nullable restore
#line (10,38)-(10,52) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\PersonHTML.cshtml"
Model.LastName

#line default
#line hidden
#nullable disable
            );
            WriteLiteral("\r\n    </p>\r\n</body>\r\n</html>");
        }
        #pragma warning restore 1998
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<dynamic> Html { get; private set; } = default!;
        #nullable disable
    }
}
#pragma warning restore 1591

#pragma checksum "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\_ViewImports.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "95493514af34e5705fffb1e5c7121f0e7abde13ee7a1cff8fbafa2085da18fff"
// <auto-generated/>
#pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCoreGeneratedDocument.Slices__ViewImports), @"mvc.1.0.view", @"/Slices/_ViewImports.cshtml")]
namespace AspNetCoreGeneratedDocument
{
    #line default
    using global::System;
    using global::System.Collections.Generic;
    using global::System.Linq;
    using global::System.Threading.Tasks;
    using global::Microsoft.AspNetCore.Mvc;
    using global::Microsoft.AspNetCore.Mvc.Rendering;
    using global::Microsoft.AspNetCore.Mvc.ViewFeatures;
#nullable restore
#line (3,2)-(4,1) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\_ViewImports.cshtml"
using System.Globalization;

#nullable disable
#nullable restore
#line (4,2)-(5,1) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\_ViewImports.cshtml"
using Microsoft.AspNetCore.Razor;

#nullable disable
#nullable restore
#line (5,2)-(6,1) "D:\gth\RSCG_Examples\v2\rscg_examples\EmbeddedResourcePropertyGenerator\src\RazorDemoSlices\RazorDemoSlices\Slices\_ViewImports.cshtml"
using Microsoft.AspNetCore.Http.HttpResults;

#line default
#line hidden
#nullable disable
    [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/Slices/_ViewImports.cshtml")]
    [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute]
    #nullable restore
    internal sealed class Slices__ViewImports : RazorSliceHttpResult
    #nullable disable
    {
        #pragma warning disable 1998
        public async override global::System.Threading.Tasks.Task ExecuteAsync()
        {
            WriteLiteral("\r\n");
            WriteLiteral("\r\n");
        }
        #pragma warning restore 1998
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!;
        #nullable disable
        #nullable restore
        [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
        public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<dynamic> Html { get; private set; } = default!;
        #nullable disable
    }
}
#pragma warning restore 1591

// <auto-generated/>

using global::System.Diagnostics.CodeAnalysis;
using global::RazorSlices;

#nullable enable

namespace RazorDemoSlices
{
    /// <summary>
    /// All calls to create Razor Slices instances via the generated <see cref="global::RazorSlices.IRazorSliceProxy"/> classes
    /// go through this factory to ensure that the generated types' Create methods are always invoked via the static abstract
    /// methods defined in the <see cref="global::RazorSlices.IRazorSliceProxy"/> interface. This ensures that the interface
    /// implementation is never trimmed from the generated types.
    /// </summary>
    /// <remarks>
    /// Workaround for https://github.com/dotnet/runtime/issues/102796
    /// </remarks>
    [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] // Hide from IntelliSense.
    internal static class RazorSlicesGenericFactory
    {
        public static RazorSlice CreateSlice<TProxy>() where TProxy : IRazorSliceProxy => TProxy.CreateSlice();

        public static RazorSlice<TModel> CreateSlice<TProxy, TModel>(TModel model) where TProxy : IRazorSliceProxy => TProxy.CreateSlice(model);
    }
}
namespace RazorDemoSlices.Slices
{
    /// <summary>
    /// Static proxy for the Razor Slice defined in <c>Slices\PersonHTML.cshtml</c>.
    /// </summary>
    public sealed class PersonHTML : global::RazorSlices.IRazorSliceProxy
    {
        [global::System.Diagnostics.CodeAnalysis.DynamicDependency(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, TypeName, "RazorDemoSlices")]
        private const string TypeName = "AspNetCoreGeneratedDocument.Slices_PersonHTML, RazorDemoSlices";
        [global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
        private static readonly global::System.Type _sliceType = global::System.Type.GetType(TypeName)
            ?? throw new global::System.InvalidOperationException($"Razor view type '{TypeName}' was not found. This is likely a bug in the RazorSlices source generator.");
        private static readonly global::RazorSlices.SliceDefinition _sliceDefinition = new(_sliceType);

        /// <summary>
        /// Creates a new instance of the Razor Slice defined in <c>Slices\PersonHTML.cshtml</c> .
        /// </summary>
        public static global::RazorSlices.RazorSlice Create()
            => global::RazorDemoSlices.RazorSlicesGenericFactory.CreateSlice<global::RazorDemoSlices.Slices.PersonHTML>();

        /// <summary>
        /// Creates a new instance of the Razor Slice defined in <c>Slices\PersonHTML.cshtml</c> with the given model.
        /// </summary>
        public static global::RazorSlices.RazorSlice<TModel> Create<TModel>(TModel model)
            => global::RazorDemoSlices.RazorSlicesGenericFactory.CreateSlice<global::RazorDemoSlices.Slices.PersonHTML, TModel>(model);

        // Explicit interface implementation
        static global::RazorSlices.RazorSlice global::RazorSlices.IRazorSliceProxy.CreateSlice() => _sliceDefinition.CreateSlice();

        // Explicit interface implementation
        static global::RazorSlices.RazorSlice<TModel> global::RazorSlices.IRazorSliceProxy.CreateSlice<TModel>(TModel model) => _sliceDefinition.CreateSlice(model);
    }
}


Code and pdf at

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

RSCG – TypedSignalR.Client

RSCG – TypedSignalR.Client
 
 

name TypedSignalR.Client
nuget https://www.nuget.org/packages/TypedSignalR.Client/
link https://github.com/nenoNaninu/TypedSignalR.Client
author nenoNaninu

Creating typed Signal R clients

 

This is how you can use TypedSignalR.Client .

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="Microsoft.AspNetCore.SignalR.Client" Version="6.0.1" />
		<PackageReference Include="TypedSignalR.Client" Version="3.6.0">
		  <PrivateAssets>all</PrivateAssets>
		  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
		</PackageReference>
	</ItemGroup>

	<ItemGroup>
	  <ProjectReference Include="..\TestSignalRCommon\TestSignalRCommon.csproj" />
	</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 Microsoft.AspNetCore.SignalR.Client;
using TestSignalRCommon;
using TestSignalRConsole;

Console.WriteLine("Hello, World!");
await Task.Delay(5_000);
HubConnection _connection = new HubConnectionBuilder()
    .WithUrl("https://localhost:7302/ChatHub")
    .Build();
await _connection.StartAsync();

_connection.On<string, string>("ReceiveMessage", (user, message) =>
{
    Console.WriteLine($" from not typed {user}: {message}");
});

await Task.Delay(30_000);
var h = TypedSignalR.Client.HubConnectionExtensions.CreateHubProxy<IHubMessage>(_connection);
await h.SendMessage("console", "message");
//TypedSignalR.Client.HubConnectionExtensions.Register<IHubMessage>(_connection,new ReceiverMessage());

Console.WriteLine("waiting for messages from Windows App");
var message = Console.ReadLine();




 

The code that is generated is

// <auto-generated>
// THIS (.cs) FILE IS GENERATED BY TypedSignalR.Client
// </auto-generated>
#nullable enable
#pragma warning disable CS1591
namespace TypedSignalR.Client
{
    internal interface IHubConnectionObserver
    {
        global::System.Threading.Tasks.Task OnClosed(global::System.Exception? exception);
        global::System.Threading.Tasks.Task OnReconnected(string? connectionId);
        global::System.Threading.Tasks.Task OnReconnecting(global::System.Exception? exception);
    }

    internal interface IHubInvoker
    {
    }

    internal interface IHubInvokerFactory
    {
    }

    internal interface IHubInvokerFactory<out T> : IHubInvokerFactory
    {
        T CreateHubInvoker(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, global::System.Threading.CancellationToken cancellationToken);
    }

    internal interface IReceiverBinder
    {
    }

    internal interface IReceiverBinder<in T> : IReceiverBinder
    {
        global::System.IDisposable Bind(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, T receiver);
    }
}
#pragma warning restore CS1591

// <auto-generated>
// THIS (.cs) FILE IS GENERATED BY TypedSignalR.Client
// </auto-generated>
#nullable enable
#pragma warning disable CS1591
#pragma warning disable CS8767
#pragma warning disable CS8613
namespace TypedSignalR.Client
{
    internal static partial class HubConnectionExtensions
    {
        private static partial global::System.Collections.Generic.Dictionary<global::System.Type, IReceiverBinder> CreateBinders()
        {
            var binders = new global::System.Collections.Generic.Dictionary<global::System.Type, IReceiverBinder>();


            return binders;
        }
    }
}
#pragma warning restore CS8613
#pragma warning restore CS8767
#pragma warning restore CS1591

// <auto-generated>
// THIS (.cs) FILE IS GENERATED BY TypedSignalR.Client
// </auto-generated>
#nullable enable
#pragma warning disable CS1591
namespace TypedSignalR.Client
{
    internal static partial class HubConnectionExtensions
    {
        public static THub CreateHubProxy<THub>(this global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, global::System.Threading.CancellationToken cancellationToken = default)
        {
            var factory = HubInvokerFactoryProvider.GetHubInvokerFactory<THub>();

            if (factory is null)
            {
                throw new global::System.InvalidOperationException($"Failed to create a hub proxy. TypedSignalR.Client did not generate source code to create a hub proxy, which type is {typeof(THub)}.");
            }

            return factory.CreateHubInvoker(connection, cancellationToken);
        }

        public static global::System.IDisposable Register<TReceiver>(this global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, TReceiver receiver)
        {
            if (receiver is null)
            {
                throw new global::System.ArgumentNullException(nameof(receiver));
            }

            if (typeof(TReceiver) == typeof(IHubConnectionObserver))
            {
                return new HubConnectionObserverSubscription(connection, (IHubConnectionObserver)receiver);
            }

            var binder = ReceiverBinderProvider.GetReceiverBinder<TReceiver>();

            if (binder is null)
            {
                throw new global::System.InvalidOperationException($"Failed to register a receiver. TypedSignalR.Client did not generate source code to register a receiver, which type is {typeof(TReceiver)}.");
            }

            var subscription = binder.Bind(connection, receiver);

            if (receiver is IHubConnectionObserver hubConnectionObserver)
            {
                subscription = new CompositeDisposable(new[] { subscription, new HubConnectionObserverSubscription(connection, hubConnectionObserver) });
            }

            return subscription;
        }
    }

    internal static partial class HubConnectionExtensions
    {
        private static partial global::System.Collections.Generic.Dictionary<global::System.Type, IHubInvokerFactory> CreateFactories();
        private static partial global::System.Collections.Generic.Dictionary<global::System.Type, IReceiverBinder> CreateBinders();

        private static class HubInvokerFactoryProvider
        {
            private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, IHubInvokerFactory> Factories;

            static HubInvokerFactoryProvider()
            {
                Factories = CreateFactories();
            }

            public static IHubInvokerFactory<T>? GetHubInvokerFactory<T>()
            {
                return Cache<T>.HubInvokerFactory;
            }

            private static class Cache<T>
            {
                public static readonly IHubInvokerFactory<T>? HubInvokerFactory = default;

                static Cache()
                {
                    if (Factories.TryGetValue(typeof(T), out var hubInvokerFactory))
                    {
                        HubInvokerFactory = hubInvokerFactory as IHubInvokerFactory<T>;
                    }
                }
            }
        }

        private static class ReceiverBinderProvider
        {
            private static readonly global::System.Collections.Generic.Dictionary<global::System.Type, IReceiverBinder> Binders;

            static ReceiverBinderProvider()
            {
                Binders = CreateBinders();
            }

            public static IReceiverBinder<T>? GetReceiverBinder<T>()
            {
                return Cache<T>.ReceiverBinder;
            }

            private static class Cache<T>
            {
                public static readonly IReceiverBinder<T>? ReceiverBinder = default;

                static Cache()
                {
                    if (Binders.TryGetValue(typeof(T), out var receiverBinder))
                    {
                        ReceiverBinder = receiverBinder as IReceiverBinder<T>;
                    }
                }
            }
        }

        private sealed class HubConnectionObserverSubscription : global::System.IDisposable
        {
            private readonly global::Microsoft.AspNetCore.SignalR.Client.HubConnection _connection;
            private readonly IHubConnectionObserver _hubConnectionObserver;

            private int _disposed = 0;

            public HubConnectionObserverSubscription(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, IHubConnectionObserver hubConnectionObserver)
            {
                _connection = connection;
                _hubConnectionObserver = hubConnectionObserver;

                _connection.Closed += hubConnectionObserver.OnClosed;
                _connection.Reconnected += hubConnectionObserver.OnReconnected;
                _connection.Reconnecting += hubConnectionObserver.OnReconnecting;
            }

            public void Dispose()
            {
                if (global::System.Threading.Interlocked.Exchange(ref _disposed, 1) == 0)
                {
                    _connection.Closed -= _hubConnectionObserver.OnClosed;
                    _connection.Reconnected -= _hubConnectionObserver.OnReconnected;
                    _connection.Reconnecting -= _hubConnectionObserver.OnReconnecting;
                }
            }
        }

        private sealed class CompositeDisposable : global::System.IDisposable
        {
            private readonly object _gate = new object();
            private readonly global::System.Collections.Generic.List<global::System.IDisposable> _disposables;

            private bool _disposed;

            public CompositeDisposable()
            {
                _disposables = new global::System.Collections.Generic.List<global::System.IDisposable>();
            }

            public CompositeDisposable(global::System.IDisposable[] disposables)
            {
                _disposables = new global::System.Collections.Generic.List<global::System.IDisposable>(disposables);
            }

            public CompositeDisposable(int capacity)
            {
                if (capacity < 0)
                {
                    throw new global::System.ArgumentOutOfRangeException(nameof(capacity));
                }

                _disposables = new global::System.Collections.Generic.List<global::System.IDisposable>(capacity);
            }

            public void Add(global::System.IDisposable item)
            {
                bool shouldDispose = false;

                lock (_gate)
                {
                    shouldDispose = _disposed;

                    if (!_disposed)
                    {
                        _disposables.Add(item);
                    }
                }

                if (shouldDispose)
                {
                    item.Dispose();
                }
            }

            public void Dispose()
            {
                var currentDisposables = default(global::System.Collections.Generic.List<global::System.IDisposable>);

                lock (_gate)
                {
                    if (_disposed)
                    {
                        return;
                    }

                    _disposed = true;
                    currentDisposables = _disposables;
                }

                foreach (var item in currentDisposables)
                {
                    if (item is not null)
                    {
                        item.Dispose();
                    }
                }

                currentDisposables.Clear();
            }
        }

        // It is not possible to avoid boxing.
        // This is a limitation caused by the SignalR implementation.
        private static class HandlerConverter
        {
            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert(global::System.Func<global::System.Threading.Tasks.Task> handler)
            {
                return args => handler();
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1>(global::System.Func<T1, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2>(global::System.Func<T1, T2, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3>(global::System.Func<T1, T2, T3, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4>(global::System.Func<T1, T2, T3, T4, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5>(global::System.Func<T1, T2, T3, T4, T5, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6>(global::System.Func<T1, T2, T3, T4, T5, T6, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, (T15)args[14]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, (T15)args[14]!, (T16)args[15]!);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert(global::System.Func<global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler(default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1>(global::System.Func<T1, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2>(global::System.Func<T1, T2, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3>(global::System.Func<T1, T2, T3, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4>(global::System.Func<T1, T2, T3, T4, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5>(global::System.Func<T1, T2, T3, T4, T5, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6>(global::System.Func<T1, T2, T3, T4, T5, T6, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> handler)
            {
                return args => handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, (T15)args[14]!, default);
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<TResult>(global::System.Func<global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler().ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, TResult>(global::System.Func<T1, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, TResult>(global::System.Func<T1, T2, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, TResult>(global::System.Func<T1, T2, T3, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, TResult>(global::System.Func<T1, T2, T3, T4, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, TResult>(global::System.Func<T1, T2, T3, T4, T5, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, (T15)args[14]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, (T15)args[14]!, (T16)args[15]!).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<TResult>(global::System.Func<global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler(default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, TResult>(global::System.Func<T1, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, TResult>(global::System.Func<T1, T2, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, TResult>(global::System.Func<T1, T2, T3, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, TResult>(global::System.Func<T1, T2, T3, T4, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, TResult>(global::System.Func<T1, T2, T3, T4, T5, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, default).ConfigureAwait(false);
                    return result;
                };
            }

            public static global::System.Func<object?[], global::System.Threading.Tasks.Task<TResult>> Convert<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(global::System.Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<TResult>> handler)
            {
                return async args =>
                {
                    var result = await handler((T1)args[0]!, (T2)args[1]!, (T3)args[2]!, (T4)args[3]!, (T5)args[4]!, (T6)args[5]!, (T7)args[6]!, (T8)args[7]!, (T9)args[8]!, (T10)args[9]!, (T11)args[10]!, (T12)args[11]!, (T13)args[12]!, (T14)args[13]!, (T15)args[14]!, default).ConfigureAwait(false);
                    return result;
                };
            }
        }
    }
}
#pragma warning restore CS1591

// <auto-generated>
// THIS (.cs) FILE IS GENERATED BY TypedSignalR.Client
// </auto-generated>
#nullable enable
#pragma warning disable CS1591
#pragma warning disable CS8767
#pragma warning disable CS8613
namespace TypedSignalR.Client
{
    internal static partial class HubConnectionExtensions
    {
        private sealed class HubInvokerFor_global__TestSignalRCommon_IHubMessage : global::TestSignalRCommon.IHubMessage, IHubInvoker
        {
            private readonly global::Microsoft.AspNetCore.SignalR.Client.HubConnection _connection;
            private readonly global::System.Threading.CancellationToken _cancellationToken;

            public HubInvokerFor_global__TestSignalRCommon_IHubMessage(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, global::System.Threading.CancellationToken cancellationToken)
            {
                _connection = connection;
                _cancellationToken = cancellationToken;
            }

            public global::System.Threading.Tasks.Task SendMessage(string user, string message)
            {
                return global::Microsoft.AspNetCore.SignalR.Client.HubConnectionExtensions.InvokeCoreAsync(_connection, nameof(SendMessage), new object?[] { user, message }, _cancellationToken);
            }
        }

        private sealed class HubInvokerFactoryFor_global__TestSignalRCommon_IHubMessage : IHubInvokerFactory<global::TestSignalRCommon.IHubMessage>
        {
            public global::TestSignalRCommon.IHubMessage CreateHubInvoker(global::Microsoft.AspNetCore.SignalR.Client.HubConnection connection, global::System.Threading.CancellationToken cancellationToken)
            {
                return new HubInvokerFor_global__TestSignalRCommon_IHubMessage(connection, cancellationToken);
            }
        }

        private static partial global::System.Collections.Generic.Dictionary<global::System.Type, IHubInvokerFactory> CreateFactories()
        {
            var factories = new global::System.Collections.Generic.Dictionary<global::System.Type, IHubInvokerFactory>();

            factories.Add(typeof(global::TestSignalRCommon.IHubMessage), new HubInvokerFactoryFor_global__TestSignalRCommon_IHubMessage());

            return factories;
        }
    }
}
#pragma warning restore CS8613
#pragma warning restore CS8767
#pragma warning restore CS1591

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/TypedSignalR.Client

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.