ABS.AccessRight.Generator 1.1.2
ABS.AccessRight - Access right generator
A helper source generator that aid in generating boilerplate access right content for some accounting software. Read through the following for a better understanding.
Example
The following example source class will be transformed and generating the next following output code:
Source:
using ABS.AccessRight.Generator; namespace ABS.AccessRight.UnitTest { public abstract class AccessRightTest { [AccessRight(Cmd = nameof(NON_ROOT))] public string NON_ROOT { get; } [AccessRight(Cmd = nameof(ADD_DOC), ParentCmd = nameof(NON_ROOT))] public string ADD_DOC { get; } [AccessRight(Cmd = nameof(LIMITED), ParentCmd = nameof(ADD_DOC), Description = "Some interesting description")] public string LIMITED { get; } [AccessRight(Cmd = "ADD_DOC2", ParentCmd = "ROOT")] public static string ADD_DOC2 { get; } } }Output:
// <auto-generated/> // This file is auto-generated by ABS.AccessRight.Generator // Do not edit this file directly, changes will be overwritten by the generator. using SomeAccounting.Authentication; using System; using System.Collections.Generic; namespace ABS.AccessRight.Generator { /// <summary> /// Reference class that contains all of the recognized access right string /// </summary> public abstract class AccessRightReference { public static string NON_ROOT = "NON_ROOT"; public static string NON_ROOT_ADD_DOC = "NON_ROOT_ADD_DOC"; public static string NON_ROOT_ADD_DOC_LIMITED = "NON_ROOT_ADD_DOC_LIMITED"; /// <summary> /// Register all available access rights to the system /// </summary> public static void RegisterAccessRights() { AccessRightMap.AddAccessRightRecord(new AccessRightRecord(NON_ROOT, null, null)); AccessRightMap.AddAccessRightRecord(new AccessRightRecord(NON_ROOT_ADD_DOC, NON_ROOT, null)); AccessRightMap.AddAccessRightRecord(new AccessRightRecord(NON_ROOT_ADD_DOC_LIMITED, NON_ROOT_ADD_DOC, "Some interesting description")); } } }So one would call
AccessRightReference.NON_ROOTto access the valueNON_ROOT, or registering all available access right viaAccessRightRerefence.RegisterAccessRights.Note: The source class must be an
abstractclass, which the generator will pickup to generated the code.
Changelog
v1.1.0:
Now the generated code's namespace and class name can be customized. It requires to add the following to the .csproj file
<PropertyGroup> <AccessRightGenerator.GeneratedNamespace>My.CustomNamespace</AccessRightGenerator.GeneratedNamespace> <AccessRightGenerator.GeneratedClassName>MyCustomClassName</AccessRightGenerator.GeneratedClassName> </PropertyGroup>The
Cmdproperty now becomes optional. The generator will automatically pick up the property's name if not supplied
v1.1.1:
- Make generated string
const, eliminatingCS0182error when using in, such as, attribute parameter
- Make generated string
v1.1.2:
- Remove period in custom build propery name that is introduced in v1.1.0, looks like following:
<PropertyGroup> <AccessRightGeneratorGeneratedNamespace>My.CustomNamespace</AccessRightGeneratorGeneratedNamespace> <AccessRightGeneratorGeneratedClassName>MyCustomClassName</AccessRightGeneratorGeneratedClassName> </PropertyGroup>
- Remove period in custom build propery name that is introduced in v1.1.0, looks like following:
TODO
Allow to customize output class name. Currently lock toAccessRightReferenceAllow to customize output namespace. Currently lock toABS.AccessRight.Generator- Perhaps more that I did not think of?
Showing the top 20 packages that depend on ABS.AccessRight.Generator.
| Packages | Downloads |
|---|---|
|
ABS.Plugin.POS
A shared library logic used to build AutoCount POS/FnB plugin
|
5 |
.NET Standard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.14.0)