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_ROOT to access the value NON_ROOT, or registering all available access right via AccessRightRerefence.RegisterAccessRights.

    Note: The source class must be an abstract class, 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 Cmd property now becomes optional. The generator will automatically pick up the property's name if not supplied

  • v1.1.1:

    • Make generated string const, eliminating CS0182 error when using in, such as, attribute parameter
  • 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>
      

TODO

  • Allow to customize output class name. Currently lock to AccessRightReference
  • Allow to customize output namespace. Currently lock to ABS.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

Version Downloads Last updated
1.1.2 4 01/13/2026
1.1.1 3 01/13/2026
1.1.0 2 01/13/2026
1.0.1 5 10/13/2025