RSCG Example – AOPMarker for CI Builds – part 30
name | AOPMarkerCI |
nuget |
https://www.nuget.org/packages/AOPMethodsCommon/ |
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
Roslyn Source Code GeneratorsFriday Links 446
[ADCES] 12 oct, FluentAssertions.Web & Bigdata2Snowflake
Prezentare 1 : Test like a Pro .NET APIs with FluentAssertions.Web
Prezentator: Adrian Iftode, https://csharpin.blogspot.com/
Descriere: With more than 100 million downloads, it is less likely you’ve never heard of Fluent Assertions. But did you know you could write your own extensions? With Fluent Assertions Extensions, you could create an assertions language that fits your business domain, by reusing the same idioms as your production code and by wrapping the business rules into simple and reusable assertions. In this presentation, we will check FluentAssertions.Web, an extension that asserts the .NET HTTP API responses, why it was built, how it can be used, and then we will deep dive into its internals in order to learn how you can build your own extension
Prezentare 2 : Moving the bigdata (lake) to cloud: Our transition to Snowflake
Prezentatori :Ionuț Bobaru & Ion Anghel (Ubisoft)
Descriere: One year ago we reached an important milestone for our projects and we realized it was time to make a decision: continue with Teradata or switch to a newer technology? Join our meetup and discover how we migrated from Teradata to Snowflake. We will tackle topics such as: architecture, stored procedures, lambda functions, step functions, Snowflake external functions, exporting and importing data to AWS S3 and others. See you there!
Va astept la https://www.meetup.com/Bucharest-A-D-C-E-S-Meetup/events/280404415/
RSCG Example – Class2Interface – part 29
name | BoilerplateFree |
nuget |
https://www.nuget.org/packages/boilerplatefree |
link | https://github.com/GeeWee/boilerplatefree |
author | Gustav Wengel |
This will generate interface from a class
The code that you start with is
[AutoGenerateInterface] public partial class Person: IPerson { public void Foo() { Console.WriteLine("Foo"); } //dummy private string s { get; set; } public int ID { get; set; } public string Name { get; set; } //dummy public static string NewID { get; set; } }
The code that you will use is
IPerson p = new Person(); p.Name = "Andrei"; p.Foo(); Console.WriteLine(p.Name);
The code that is generated is
public interface IPerson { public void Foo(); public int ID {get; set; } public string Name {get; set; } }
Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/Class2Interface
All RSCG
Roslyn Source Code GeneratorsFriday Links 445
RSCG Example – ToStringDebugger – part 28
name | StructRecordsGenerator |
nuget |
https://www.nuget.org/packages/StructRecordGenerator/ |
link | https://github.com/SergeyTeplyakov/StructRecordsGenerator |
author | Sergey Teplyakov |
This will generate code .ToString. Usefull for debugging
The code that you start with is
[StructGenerators.GenerateToString(PrintTypeName = true)] class Person { [Required] public string FirstName { get; set; } public string LastName { get; set; } }
The code that you will use is
var p = new Person(); p.FirstName = "Andrei"; //put here a debug watch to see p Console.WriteLine(p.ToString());
The code that is generated is
partial class Person { /// <inheritdoc/> public override string ToString() { var sb = new StringBuilder(); sb.Append("Person "); sb.Append("{ "); if (PrintMembers(sb)) { sb.Append(" "); } sb.Append("}"); return sb.ToString(0, Math.Min(sb.Length, /*String rep limit*/ 1024)); } /// <summary> /// Prints the content of the instance into a given string builder. /// </summary> protected virtual bool PrintMembers(StringBuilder sb) { sb.Append("s = "); sb.Append((object)s); sb.Append(", "); sb.Append("ID = "); sb.Append(ID); sb.Append(", "); sb.Append("FirstName = "); sb.Append((object)FirstName); sb.Append(", "); sb.Append("LastName = "); sb.Append((object)LastName); return true; } }
Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/DebuggerToString
All RSCG
Roslyn Source Code GeneratorsFriday Links 444
RSCG Example–TimeBombComment–part 27
name | RSCG_TimeBombComment |
nuget |
https://www.nuget.org/packages/RSCG_TimeBombComment/ |
link | http://msprogrammer.serviciipeweb.ro/category/roslyn/ |
author | Andrei Ignat |
This will generate an error from the comment after a certain date
The code that you start with is
//TB: 2021-09-13 this is a comment transformed into an error //TB: and this is a warning //TB: 9999-12-30 and this will not appear Console.WriteLine("See the TB comment above ? ");
The code that you will use is
//TB: yyyy-MM-dd this is a comment transformed into an error
The code that is generated is
2>src\RSCG_TimeBombComment\Console_TimeBombComment\Program.cs(9,13,9,73): error TB: this is a comment transformed into an error 2>src\RSCG_TimeBombComment\Console_TimeBombComment\Program.cs(10,13,10,40): warning TB: and this is a warning
Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/TimeBombComment