| 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
<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
using DemoClass; Person person = new Person(); person.Name = "Andrei Ignat"; Console.WriteLine(person.Name); Console.WriteLine(Person.ThisClass.FullName);
namespace DemoClass;
[ThisClass]
internal partial class Person
{
    public string Name { get; set; }
    public string ClassName => ThisClass.FullName;
}
The code that is generated is
// <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";
    }
}
// <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
Leave a Reply