Category: roslyn
-
AOPMethods–dogfooding
I was trying to apply AOPMethods to – surprise! – AOPMethods project itself. And I have discovered a new reason: I do not want to make the methods public. I just want to put try/catch around them to know what is wrong. The fast – and not so good – idea was to transform MethodPrefix…
-
AOP Methods–Problems in running and solving
The problems that I have encountered were: 1. The ThisAssembly RoslynGenerator that I use should not be put as reference in the nuget. I have fixed this by adding <PackageReference Include=”ThisAssembly.AssemblyInfo” Version=”1.0.0″ ReferenceOutputAssembly=”false” /> 2. I have problems generating code to async code with Task . The problem was that I have added logging (…
-
AOP Methods–Code
The code is not so much different from SkinnyControllers : Implement ISourceGenerator,putting the Generator attribute on the class [Generator] public partial class AutoActionsGenerator : ISourceGenerator inspecting the classes if they have the common attribute,generating code with Scriban The problem was : How can the AOPMethods can differentiate between the private function that must be made…
-
AOP Methods–Introduction
As I have done with Roslyn for SkinnyControllers,I said – what about generating public methods at compile time ? For example,what if this method private string pubFullName() { return FirstName + ” ” + LastName; } is transformed into this public string FullName( [CallerMemberName] string memberName = “”, [CallerFilePath] string sourceFilePath = “”, [CallerLineNumber]…
-
AutoActions for Skinny controllers–custom template
Now I want to let the user make his own template. For this,I have enriched the attribute AutoActionsAttribute with a public string CustomTemplateFileName { get; set; } The code was pretty easy,just reading from GeneratorExecutionContext . AdditionalFiles instead of reading from the template in the dll There are 2 small catches 1…
-
AutoActions for Skinny controllers–code improvements and more docs
I realized that this code Assembly.GetExecutingAssembly(); was executing for each controller. So I decided to move to a class variable and attribute once. Also,I may want to have all fields – so I decided to express via a special field * The code modifications were,thanks to Linq,pretty small: bool All = fields.Contains(“*”); var memberFields =…
-
AutoActions for Skinny controllers-documentation improvements
One improvement is to move Initialize in other partial class. . It was difficult every time I need to activate the debugger public void Initialize(GeneratorInitializationContext context) { context.RegisterForSyntaxNotifications(() => new SyntaxReceiverFields()); //in development //Debugger.Launch(); } Second was to improve the Nuget package description. I have added <Version>2020.11.28.2108</Version> <Authors>Andrei Ignat</Authors> <PackageTags>RoslynCodeGenerators C# CSharp SkinnyControllers</PackageTags> <PackageProjectUrl>https://github.com/ignatandrei/AOP_With_Roslyn</PackageProjectUrl> …
-
AutoActions for Skinny controllers–second template
The second template was pretty easy. All the date was inside the class definition : class ClassDefinition { public string ClassName; public string NamespaceName; public Dictionary<string,MethodDefinition[]> DictNameField_Methods; public string version = ThisAssembly.Info.Version; } class MethodDefinition { public string Name { get; set; } public string FieldName { get; set; } public string ReturnType; public…
-
AutoActions for Skinny controllers- templating-part2
Now I want to add templates to my controller generators . But this feature changed the whole perspective about the project. Why ? Because a template do not apply just to a field – but to the whole controller. So instead of having attributes on the field [AutoActions] private readonly RepositoryWF repository; I will have…
-
AutoActions for Skinny controllers–user customization
The generation of controllers actions is now very rude: Http Method: if the method has no arguments,I assume GET . Else it is POST How I can handle pure full REST API generation ? How I can handle level 3 REST API – https://martinfowler.com/articles/richardsonMaturityModel.html ? How I can handle any other models,like https://blog.ploeh.dk/2020/10/26/fit-urls/ What is…