RSCG Example – AOPMarker for CI Builds – part 30

 

 

name AOPMarkerCI
nuget

https://www.nuget.org/packages/AOPMethodsCommon/
https://www.nuget.org/packages/AOPMethodsGenerator/

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

This will tracing methods marked with AOPMarkerMethod in CI builds. Does not affect the code run by the programmer.
 

The code that you start with is


    using AOPMethodsCommon;

    using System;

    using System.Threading.Tasks;

    

    namespace AOPMarkerCI

    {

        [AutoMethods(template = TemplateMethod.CustomTemplateFile, MethodPrefix = "auto", CustomTemplateFileName = "../AutoMethod.txt")]

        partial class UnderTest

        {

            [AOPMarkerMethod]

            public async Task<int> Method1()

            {

                await Task.Delay(1000);

                var ret = Method2(DateTime.Now);

                return ret % 2 == 0 ? 1 : 0;

            }

            [AOPMarkerMethod]

            private int Method2(DateTime now)

            {

                return now.Second;

            }

    

        }

    }


The code that you will use is



    Console.WriteLine("Run the autoci file");

    var underTest = new UnderTest();

    int i = await underTest.Method1();

    Console.WriteLine($"result:{i}");

 

The code that is generated is


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

    // <auto-generated>

    //     This code was generated by a tool.

    //

    //     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.CodeDom.Compiler;

    using System.Runtime.CompilerServices;

    using System.Diagnostics;

    namespace AOPMarkerCI {

    

        [GeneratedCode("AOPMethods", "2021.6.11.907")]

        [CompilerGenerated]

        public partial class UnderTest{

            //autoMethod1

                

            public  async  System.Threading.Tasks.Task<int> Method1 (){

    

         Console.WriteLine("start method autoMethod1 at " +utcTime);

    

                try{

                     return   await  autoMethod1();

                }

                catch(Exception ex){

                    Console.WriteLine($"--autoMethod1 exception {ex.Message}");

                    throw;

                }

                finally{

                        utcTime =System.DateTime.UtcNow;

                    Console.WriteLine("end method autoMethod1");                

                }

    

    

            }//end Method1

            

                    //autoMethod2

                

            public  int Method2 (System.DateTime now){

                   var utcTime =System.DateTime.UtcNow;

                 

                   Console.WriteLine("start method autoMethod2 at " +utcTime);

                    string valnow ;

                    try{

                        valnow = System.Text.Json.JsonSerializer.Serialize(now);

                    }

                    catch(Exception ex){

                        valnow = "Error serializing parameter now : "+ ex.Message;

                    }

                    Console.WriteLine("Argument_now :" + valnow);

                    

                 

                

    

                try{

                     return   autoMethod2(now);

                }

                catch(Exception ex){

                    Console.WriteLine($"--autoMethod2 exception {ex.Message}");

                    throw;

                }

                finally{

                        utcTime =System.DateTime.UtcNow;

                    Console.WriteLine("end method autoMethod2");                

                }

    

    

            }//end Method2

            

            

        }

     }

    

    

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

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