Category: roslyn

RSCG Example–ApparatusAOT–part 26

 

 

name ApparatusAOT
nuget

https://www.nuget.org/packages/Apparatus.AOT.Reflection/

link https://github.com/byme8/Apparatus.AOT.Reflection
author Stanislav Silin

This will generate code for investigating at runtime the properties of an object
 

The code that you start with is


    //no special requirements

    class Person

    {

        [Required]

        public string FirstName { get; set; }

        public string LastName { get; set; }

    }


The code that you will use is



    var pOldPerson = new Person();

    pOldPerson.FirstName = "Andrei";

    

    var prop = pOldPerson.GetProperties().Values ;

    foreach (var item in prop)

    {

        Console.WriteLine($"{item.Name} Attr: {item.Attributes.Length} value {item.Name}");

        if(item.TryGetValue(pOldPerson, out var val)){

            Console.WriteLine("value : " + val);

        }

        

    }            

 

The code that is generated is


    using System;

    using System.Linq;

    

    namespace Apparatus.AOT.Reflection

    {

        public static class CopyConstructor_PersonExtensions

        {

            [global::System.Runtime.CompilerServices.ModuleInitializer]

            public static void Bootstrap()

            {

                MetadataStore<global::CopyConstructor.Person>.Data = _lazy;

            }

    

            private static global::System.Lazy<global::System.Collections.Generic.IReadOnlyDictionary<string, IPropertyInfo>> _lazy = new global::System.Lazy<global::System.Collections.Generic.IReadOnlyDictionary<string, IPropertyInfo>>(new global::System.Collections.Generic.Dictionary<string, IPropertyInfo>

            {

                { "FirstName", new global::Apparatus.AOT.Reflection.PropertyInfo<global::CopyConstructor.Person,string>(

                            "FirstName", 

                            new global::System.Attribute[] 

                            {

                                new global::System.ComponentModel.DataAnnotations.RequiredAttribute(),

                            }, 

                            instance => instance.FirstName, (instance, value) => instance.FirstName = value)

                    },

                { "LastName", new global::Apparatus.AOT.Reflection.PropertyInfo<global::CopyConstructor.Person,string>(

                            "LastName", 

                            new global::System.Attribute[] 

                            {

                                

                            }, 

                            instance => instance.LastName, (instance, value) => instance.LastName = value)

                    },

            }); 

    

    

            internal static global::System.Collections.Generic.IReadOnlyDictionary<string, IPropertyInfo> GetProperties(this global::CopyConstructor.Person value)

            {

                return _lazy.Value;

            }

        }

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/ApparatusAOT

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

RSCG Example–AppSettings editor–part 25

 

 

name AppSettingsEditor
nuget

https://www.nuget.org/packages/appSettingsEditor/

link http://msprogrammer.serviciipeweb.ro/category/roslyn/
author Andrei Ignat

This will generate classes code from appsettings . Additionally , it generates API controller for editing and an UI interface
 

The code that you start with is


    {

      "Logging": {

        "LogLevel": {

          "Default": "Information",

          "Microsoft": "Warning",

          "Microsoft.Hosting.Lifetime": "Information"

        }

      },

      "AllowedHosts": "*"

    }


The code that you will use is



    endpoints.MapSettingsView<SettingsJson.appsettings>(Configuration);

 

The code that is generated is


    //------------------------------------------------------------------------------                                                                       

    // <auto-generated>

    //     This code was generated by a tool.

    //     Runtime Version:

    //

    //     Changes to this file may cause incorrect behavior and will be lost if

    //     the code is regenerated.

    // </auto-generated>

    //------------------------------------------------------------------------------

    using System;

    using System.Collections.Generic;

    using System.Runtime.Serialization;

    using Microsoft.Extensions.Configuration;

    using appSettingsEditor;

    namespace SettingsEditor.SettingsJson

    {

    

        //[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]

        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("appSettingsEditorAPI", "2021.3.21.2300")]

        public partial class LogLevel: IAppSettingsConfig<LogLevel> 

        {

            public object GetFromPropertyName(string propName, bool returnNull =false){

                

                propName=propName?.ToUpper();

                

                switch(propName){

                    

                    case "DEFAULT":

                        return this.Default ;

                    

                    case "MICROSOFT":

                        return this.Microsoft ;

                    

                    case "MICROSOFTHOSTINGLIFETIME":

                        return this.MicrosoftHostingLifetime ;

                    

                    default:

                        if(returnNull)

                            return null;

    

                        throw new ArgumentException("cannot found from LogLevel prop "+propName);            

    

                }

                

                

            }

    

            public IEnumerable<string> Properties(){

                

                    yield return "Default" ;

                

                    yield return "Microsoft" ;

                

                    yield return "MicrosoftHostingLifetime" ;

                

                yield break;

            }

            

            [System.Text.Json.Serialization.JsonPropertyName("Default")]

            public string Default { get; set; }

            

            [System.Text.Json.Serialization.JsonPropertyName("Microsoft")]

            public string Microsoft { get; set; }

            

            [System.Text.Json.Serialization.JsonPropertyName("Microsoft.Hosting.Lifetime")]

            public string MicrosoftHostingLifetime { get; set; }

            

            public  LogLevel LoadFromConfig(IConfiguration config)

            { 

                

                    config.GetSection("Logging.LogLevel").Bind(this);

                    return this;

                

            }

        }

    

        //[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]

        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("appSettingsEditorAPI", "2021.3.21.2300")]

        public partial class Logging: IAppSettingsConfig<Logging> 

        {

            public object GetFromPropertyName(string propName, bool returnNull =false){

                

                propName=propName?.ToUpper();

                

                switch(propName){

                    

                    case "LOGLEVEL":

                        return this.LogLevel ;

                    

                    default:

                        if(returnNull)

                            return null;

    

                        throw new ArgumentException("cannot found from Logging prop "+propName);            

    

                }

                

                

            }

    

            public IEnumerable<string> Properties(){

                

                    yield return "LogLevel" ;

                

                yield break;

            }

            

            [System.Text.Json.Serialization.JsonPropertyName("LogLevel")]

            public LogLevel LogLevel { get; set; }

            

            public  Logging LoadFromConfig(IConfiguration config)

            { 

                

                    config.GetSection("Logging").Bind(this);

                    return this;

                

            }

        }

    

        //[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]

        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("appSettingsEditorAPI", "2021.3.21.2300")]

        public partial class appsettings: IAppSettingsConfig<appsettings> 

        {

            public object GetFromPropertyName(string propName, bool returnNull =false){

                

                propName=propName?.ToUpper();

                

                switch(propName){

                    

                    case "LOGGING":

                        return this.Logging ;

                    

                    case "ALLOWEDHOSTS":

                        return this.AllowedHosts ;

                    

                    default:

                        if(returnNull)

                            return null;

    

                        throw new ArgumentException("cannot found from appsettings prop "+propName);            

    

                }

                

                

            }

    

            public IEnumerable<string> Properties(){

                

                    yield return "Logging" ;

                

                    yield return "AllowedHosts" ;

                

                yield break;

            }

            

            [System.Text.Json.Serialization.JsonPropertyName("Logging")]

            public Logging Logging { get; set; }

            

            [System.Text.Json.Serialization.JsonPropertyName("AllowedHosts")]

            public string AllowedHosts { get; set; }

            

            public  appsettings LoadFromConfig(IConfiguration config)

            { 

                

                    return config.Get<appsettings>();

                

            }

        }

    

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/appSettingsEditor

RSCG Example–Static To Interface–part 24

 

 

name Static To Interface
nuget

https://www.nuget.org/packages/RSCG_Static/

link http://msprogrammer.serviciipeweb.ro/category/roslyn/
author Andrei Ignat

This will generate code for any static properties of a class to generate interface, record and a class with real behaviour
 

The code that you start with is


    public partial class Helpers

    {

    public partial ISystem_DateTime FromStaticDate();

    }


The code that you will use is



    var dateStatic1 = (new Helpers().FromStaticDate());//static        

    var dateStatic2 = recISystem_DateTime.MakeNew();//static

    var dateVar3 = new clsISystem_DateTime(); //variable = real 

    await Task.Delay(10 * 1000);

    Console.WriteLine(dateStatic1.Now.Second);

    Console.WriteLine(dateStatic2.Now.Second);

    Console.WriteLine(dateVar3.Now.Second);

 

The code that is generated is


    namespace RSCG_Static_Console { 

    public interface ISystem_DateTime {

    System.DateTime Now  {get;}

    System.DateTime UtcNow  {get;}

    System.DateTime Today  {get;}

    }// interface

    //now the partial class

    public record recISystem_DateTime (System.DateTime Now,System.DateTime UtcNow,System.DateTime Today) : ISystem_DateTime

    { 

    public static recISystem_DateTime MakeNew() {

    return new recISystem_DateTime(System.DateTime.Now,System.DateTime.UtcNow,System.DateTime.Today);

    } //end makenew

    } //end record

    public class clsISystem_DateTime : ISystem_DateTime 

    { 

    public  System.DateTime Now  {get { return System.DateTime.Now; } }

    public  System.DateTime UtcNow  {get { return System.DateTime.UtcNow; } }

    public  System.DateTime Today  {get { return System.DateTime.Today; } }

    } //end record

    partial class Program {

    public partial ISystem_DateTime FromStaticDate() {

    return recISystem_DateTime.MakeNew();

    } // method

    } // class

    } // namespace

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/StaticToInterface

RSCG Example – Tiny Types – Part 23

 

 

name BaseTypes
nuget

https://www.nuget.org/packages/AndreasDorfer.BaseTypes/

link https://github.com/Andreas-Dorfer/base-types
author Andreas Dorfer

Generated tiny types from any value type
 

The code that you start with is


    [Int] public partial record DepartmentId;

    public Employee GetFromId(int idDepartment, int idEmployee)

    {

        

        return new Employee()

        {

            ID = idEmployee,

            DepartmentId = idDepartment,

            Name = "Andrei " + idEmployee

    

        };

    }

    public Employee GetFromId(DepartmentId departmentId,  EmployeeId employeeId)

    {

        return GetFromId(departmentId, employeeId);

    }


The code that you will use is



    e.GetFromId(10, 34);

    e.GetFromId(new DepartmentId(34), new EmployeeId(10));

 

The code that is generated is


    [System.ComponentModel.TypeConverter(typeof(AD.BaseTypes.Converters.BaseTypeTypeConverter<DepartmentId, int>))]

    [System.Text.Json.Serialization.JsonConverter(typeof(AD.BaseTypes.Json.BaseTypeJsonConverter<DepartmentId, int>))]

    sealed partial record DepartmentId : System.IComparable<DepartmentId>, System.IComparable, AD.BaseTypes.IBaseType<int>

    {

        public DepartmentId(int value)

        {

            this.Value = value;

        }

        public int Value { get; }

        public override string ToString() => Value.ToString();

        public int CompareTo(object? obj) => CompareTo(obj as DepartmentId);

        public int CompareTo(DepartmentId? other) => other is null ? 1 : System.Collections.Generic.Comparer<int>.Default.Compare(Value, other.Value);

        public static implicit operator int(DepartmentId item) => item.Value;

        public static DepartmentId Create(int value) => new(value);

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/TinyTypes

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

RSCG Example–SourceInject- part 22

   

name SourceInject
nuget

https://www.nuget.org/packages/SourceInject/

link https://github.com/giggio/sourceinject
author Giovanni Bassi

Auto register services in startup   The code that you start with is


    using Microsoft.Extensions.DependencyInjection;

    using System;

    using System.Threading.Tasks;

    

    namespace AutoRegisterBL

    {

        [Inject(ServiceLifetime.Transient)]

        public class Repo

        {

            public async Task<person> GetFromId(int id)

            {

                await Task.Delay(1000);

                return new Person()

                {

                    ID = id,

                    Name = " Andrei Ignat " + id

                };

            }

        }

    }


The code that you will use is



    //in startup.cs

    services.DiscoverInAutoRegisterBL();

   The code that is generated is


    // <auto-generated>

    using Microsoft.Extensions.DependencyInjection;

    

    public static class GeneratedServicesExtension

    {

        public static void DiscoverInAutoRegisterBL(this IServiceCollection services) =&gt; services.Discover();

        internal static void Discover(this IServiceCollection services)

        {

            services.AddTransient<autoregisterbl.repo>();

    

        }

    }

    

    public static class AutoRegisterBLDiscoverer

    {

        public static void Discover(IServiceCollection services) =&gt; services.Discover();

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/AutoRegister

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

RSCG example–Query Generator–part 21

   

name DatabaseToWebAPI
nuget

https://www.nuget.org/packages/QueryGenerator/

link http://msprogrammer.serviciipeweb.ro/category/roslyn/
author Andrei Ignat

This will generate code (WebAPI/Swagger) for any table/view from SqlServer. You can see the table via Angular   The code that you start with is


    //add queries.json with all the connection string and tables necessary

    //add in templates folder the files to generate controllers

    using RoslynQueryGenerator;

    using System.Collections.Generic;

    //TODO : modify namespace

    namespace WebFromQuery.Classes

    {

        public class FieldDescription

        {

            public string ItemName { get; set; }

            public string QueryName { get; set; }

    

            public string FieldName { get; set; }

            public string FieldType { get; set; }

    

            public SearchField DefaultValue { get; set; }

        }

        public class DisplayData

        {

            public string QueryName { get; set; }

            public string ItemName { get; set; }

            public FieldDescription[] FieldNames { get; set; }

            public Dictionary<string  , object="">[] Values { get; set; }

        }

      

    }

    


The code that you will use is



    //In Startup

    services.AddFactoryGenerated();

    app.UseDefaultFiles();

    app.UseStaticFiles();

   The code that is generated is


    //ApplicationDbContext : too much lines - see project

    //Controllers : too much lines - see project

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/QueryGenerator

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

RSCG Example–HttpClientGenerator–part 19

 

 

name HttpClientGenerator
nuget

https://www.nuget.org/packages/HttpClientGenerator/

link https://github.com/Jalalx/HttpClientCodeGenerator
author Jalal Amini Robati

HttpClientGenerator is a tool that uses Roslyn code generator feature to write boilerplate HttpClient code for you.
 

The code that you start with is


    public partial class WeatherService

    {

       [HttpGet(

    WeatherForecast/{id}

    )]

       public partial Task<WeatherForecast> GetWeather(int id);

    

        [HttpGet(

    WeatherForecast

    )]

        public partial Task<WeatherForecast[]> GetAllWeather();  

    }


The code that you will use is



    using (var client = new HttpClient())                              

    {

        client.BaseAddress = new Uri(

    http://localhost:5000

    );

        var userService = new WeatherService(client);

        var w = await userService.GetWeather(1);

        Console.WriteLine($

    {w.Summary}

    );

        var q = await userService.GetAllWeather();

        Console.WriteLine($

    {q[0].Summary}

    );

    }

 

The code that is generated is


    public partial async System.Threading.Tasks.Task<BL.WeatherForecast> GetWeather(int id)

    {

        const string @___httpMethod = 

    GET

    ;

        

        var @___path = 

    WeatherForecast/{id}

    ;

        var @___routes = new Dictionary<string, object>();

        @___routes[

    id

    ] = id;

        

        var @___queryParams = new Dictionary<string, object>();

        // Query String dictionary goes here...

        

        var @___headers = new Dictionary<string, string>();

        // Header dictionary goes here...

        

        return await HttpClientGenerator.Shared.HttpClientHelper.SendAsync<BL.WeatherForecast>(_httpClient, @___httpMethod, @___path, @___headers, @___routes, @___queryParams);

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/HttpClientCodeGenerator

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

RSCG Example–CI Version–part 18

 

name RSCG_AMS
nuget https://www.nuget.org/packages/AMS_Base
https://www.nuget.org/packages/AMSWebAPI
https://www.nuget.org/packages/RSCG_AMS
link https://github.com/ignatandrei/RSCG_AMS
author Andrei Ignat

The AMS will add in the CI the version and creator to your project.See https://netcoreblockly.herokuapp.com/ams for an example   The code that you start with is


    <packagereference include="AMS_Base">

    <packagereference include="AMSWebAPI">

    <packagereference include="RSCG_AMS" outputitemtype="Analyzer" referenceoutputassembly="false">


The code that you will use is



    app.UseEndpoints(endpoints =&gt;

    {

        endpoints.MapControllers();

        endpoints.UseAMS();

    });

The code that is generated is


    using System;

    using AMS_Base;

    namespace AMSExample { 

        /// <summary>

        /// this is the About My Software for 65788572124102115119116110

        /// </summary>

        public class XAboutMySoftware_65788572124102115119116110 :AboutMySoftware {

            /// <summary>

            /// starts when this module is loaded and 

            /// add the AMS tot the 

            /// </summary>

            [System.Runtime.CompilerServices.ModuleInitializer]

            public static void Add_AboutMySoftware_65788572124102115119116110(){

                AboutMySoftware.AddDefinition("AMSExample",new  XAboutMySoftware_65788572124102115119116110());  

            }

            /// <summary>

            /// constructor

            /// for AMS 65788572124102115119116110

            /// </summary>

            public XAboutMySoftware_65788572124102115119116110(){

                AssemblyName ="AMSExample" ; 

                DateGenerated = DateTime.ParseExact("20210717034910", "yyyyMMddHHmmss", null); 

                CommitId  = "not in a CI run" ; 

                RepoUrl ="https://ignatandrei.github.io/RSCG_AMS/runtimeMessages/NotFound.md" ; 

                CISourceControl = "not in a CI run" ; 

                SourceCommit = "https://ignatandrei.github.io/RSCG_AMS/runtimeMessages/NotFound.md" ; 

                Authors= "";

                Version= "";  

                User = "Surface1";

            }

            

        }

           

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/CI_Version

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

RSCG-Integrating with CI Only – part 10

The integration with CI providers is enough straightforward – just see what environments variable those providers have. GitLab and Github has enough documentation – at https://docs.gitlab.com/ee/ci/variables/ and https://docs.github.com/en/actions/reference/environment-variables 

What I have forgot is that there are also CI providers without having necessary source control.

For example AzureDevOps can execute code taken from GitHub

More than that  Heroku stack , that has not source control , have dispersed info – see https://devcenter.heroku.com/changelog-items/630 about SOURCE_VERSION – and no more else about the what other variables it has. I have obtained those via RSCG – but no indication about what is the source control comes.

What can I do ? The solution is to avert the users – I have created https://ignatandrei.github.io/RSCG_AMS/runtimeMessages/NotFound.md .

RSCG–Template Rendering- part 17

 

name Transplator
nuget https://www.nuget.org/packages/Transplator/
link https://github.com/atifaziz/Transplator/
author Atif Aziz

The Transplator is a small fast rendering engine to allow you to make rendering from any class instance.   The code that you start with is


    {%

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Rendering;

    

    static partial class EmployeeRendering

    {

        public static string Render(params Employee[] employees)

        {

            var sb = new StringBuilder();

            int i= 0;

    -%}

    Number Employees: {% employees?.Length %}

        {%~ foreach (var emp in employees) { 

        i++;

        ~%}

        {% i %}. {% emp.Name %}  it is in {% emp.Department?.Name %}

        {%~ } ~%}

    {%

            return sb.ToString();

    

            void WriteText(string value) =&gt; sb.Append(value);

            void WriteValue(object value) =&gt; sb.Append(value);

        }

    }

    ~%}


The code that you will use is



    var IT = new Department();

    IT.Name = "IT";

    var e = new Employee();

    e.ID = 10;

    e.Name = "Andrei Ignat";

    e.Department = IT;

    var render = EmployeeRendering.Render(e);

    Console.WriteLine(render);

The code that is generated is


    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Rendering;

    

    static partial class EmployeeRendering

    {

        public static string Render(params Employee[] employees)

        {

            var sb = new StringBuilder();

            int i= 0;

    WriteText(@"Number Employees: ");

    WriteValue(employees?.Length);

    WriteText(@"

    ");

    foreach (var emp in employees) { 

        i++;

       WriteText(@"    ");

    WriteValue(i);

    WriteText(@". ");

    WriteValue(emp.Name);

    WriteText(@"  it is in ");

    WriteValue(emp.Department?.Name);

    WriteText(@"

    ");

    }

            return sb.ToString();

    

            void WriteText(string value) =&gt; sb.Append(value);

            void WriteValue(object value) =&gt; sb.Append(value);

        }

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/TemplateRender

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

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.