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

NET Battle & Encrypted FileSystem

Presentation 1 : .NET Battle
Presenter 1: Andrei Ignat , http://msprogrammer.serviciipeweb.ro/
Description 1: We will present various .NET features / tools and let the people decide what is more usefull

Presentation 2 : The Hitchhiker’s Guide to Building an Encrypted Filesystem in Rust
Presenter 2 : Radu Marias, https://xorio.rs/
Description 2:
An encrypted file system written in Rust that is mounted with FUSE on Linux. It can be used to create encrypted directories.
You can then safely backup the encrypted directory to an untrusted server without worrying about the data being exposed. You can also store it in any cloud storage like Google Drive, Dropbox, etc. and have it synced across multiple devices.
You can use it as CLI or as a library to build your custom FUSE implementation or other apps that works with encrypted data.
intro to AEAD encryption
– how to build an encrypted fikesystem, and tips& tricks
– key features that separate us from competitors (Edited)

Video call link: https://meet.google.com/hkc-mnzz-wkf

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

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.