Giter VIP home page Giter VIP logo

thisclass's Introduction

ThisClass

Exposes class and type information as constants in the ThisClass class using source generators powered by Roslyn, inspired by ThisAssembly.

ThisClass

Add the ThisClassAttribute to generate type information for a class.

[ThisClass]
partial class Demo
{
    public Demo()
    {
        Logger.Info($"Hello from {ThisClass.FullName}"); // SampleApp.Demo
    }
}

NLog.Extensions.ThisClass

Create class loggers without using reflection.

using SomeNamespace;

namespace SampleApp.NLog
{
    ...
    namespace AnotherNamespace
    {
        using SomeOtherNamespace;
        [ClassLoggerLazy]
        partial class Demo2<T> : SomeInterface<T> where T : SomeOtherInterface
        {
            public static void SayHello()
            {
                Logger.Info("Hello");
            }

            [ClassLogger]
            internal partial class NestedClass : SomeInterface<SomeOtherInterface>
            {
            }
        }
    }
}

Looks like this behind the scenes

// <auto-generated/>
#nullable enable
namespace SampleApp.NLog
{
    partial class Demo1
    {
        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 = "SampleApp.NLog.Demo1";
        }
    }
}

// <auto-generated/>
#nullable enable
namespace SampleApp.NLog
{
    namespace AnotherNamespace
    {
        using SomeOtherNamespace;

        partial class Demo2<T> : global::SomeNamespace.SomeInterface<T> where T : global::SomeOtherNamespace.SomeOtherInterface
        {
            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 = "SampleApp.NLog.AnotherNamespace.Demo2";
            }

            private static global::NLog.Logger? __loggerLazy;
            private static global::NLog.Logger Logger => __loggerLazy ??= global::NLog.LogManager.GetLogger(ThisClass.FullName);
        }
    }
}

// <auto-generated/>
#nullable enable
namespace SampleApp.NLog
{
    namespace AnotherNamespace
    {
        using SomeOtherNamespace;

        partial class Demo2<T> : global::SomeNamespace.SomeInterface<T> where T : global::SomeOtherNamespace.SomeOtherInterface
        {
            partial class NestedClass : global::SomeNamespace.SomeInterface<global::SomeOtherNamespace.SomeOtherInterface>
            {
                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 = "SampleApp.NLog.AnotherNamespace.Demo2.NestedClass";
                }

                private static readonly global::NLog.Logger Logger = global::NLog.LogManager.GetLogger(ThisClass.FullName);
            }
        }
    }
}

thisclass's People

Contributors

trympet avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.