RSCG – ThisClass

 
 

name ThisClass
nuget https://www.nuget.org/packages/ThisClass/
link https://github.com/trympet/ThisClass
author Trym Lund Flogard

Generate full class name from class

 

This is how you can use ThisClass .

The code that you start with is

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
<Project Sdk="Microsoft.NET.Sdk">
 
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>
 
    <ItemGroup>
        <PackageReference Include="ThisClass" Version="1.5.11" />
    </ItemGroup>
    <PropertyGroup>
        <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
        <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
    </PropertyGroup>
 
</Project>

The code that you will use is

1
2
3
4
5
6
using DemoClass;
 
Person person = new Person();
person.Name = "Andrei Ignat";
Console.WriteLine(person.Name);
Console.WriteLine(Person.ThisClass.FullName);
1
2
3
4
5
6
7
8
namespace DemoClass;
[ThisClass]
internal partial class Person
{
    public string Name { get; set; }
 
    public string ClassName => ThisClass.FullName;
}

 

The code that is generated is

01
02
03
04
05
06
07
08
09
10
11
12
13
14
// <auto-generated/>
#pragma warning disable CS0108, CS1591, CS1573, CS0465, CS0649, CS8019, CS1570, CS1584, CS1658, CS0436, CS8981
#nullable enable
namespace DemoClass;
partial class Person
{
    public static partial class ThisClass
    {
        /// <summary>
        /// Gets the fully qualified name of the parent class, including the namespace but not the assembly.
        /// </summary>
        public const string FullName = "DemoClass.Person";
    }
}
1
2
3
4
5
6
7
// <auto-generated/>
#pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981
using System;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false, AllowMultiple = true)]
sealed partial class ThisClassAttribute : Attribute
{
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisClass