Git Product home page Git Product logo

f0.generators's Introduction

f0.generators's People

Contributors

flash0ver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

f0.generators's Issues

Generated `System.Enum.IsDefined` method

// <auto-generated/>

#nullable enable

using Microsoft.Extensions.Logging;

namespace F0.Generated;

internal static class EnumInfo
{
    public static bool IsDefined(LogLevel value)
    {
        return value switch
        {
            LogLevel.Trace => true,
            LogLevel.Debug => true,
            LogLevel.Information => true,
            LogLevel.Warning => true,
            LogLevel.Error => true,
            LogLevel.Critical => true,
            LogLevel.None => true,
            _ => false,
        };
    }
}

Generated `System.Enum.ToString(string? format)` method

// <auto-generated/>
#nullable enable

using Microsoft.Extensions.Logging;

namespace F0.Generated;

internal static class EnumInfo
{
    public static string? ToString(LogLevel value, string? format)
    {
        if (String.IsNullOrEmpty(format))
        {
            return EnumInfo.GetName(value);
        }

        if (format.Length == 1)
        {
            if (format[0] is 'G' or 'g')
            {
                return EnumInfo.GetName(value);
            }

            if (format[0] is 'D' or 'd')
            {
                return value switch
                {
                    LogLevel.Trace => "0",
                    LogLevel.Debug => "1",
                    LogLevel.Information => "2",
                    LogLevel.Warning => "3",
                    LogLevel.Error => "4",
                    LogLevel.Critical => "5",
                    LogLevel.None => "6",
                    _ => null,
                };
            }

            if (format[0] is 'X' or 'x')
            {
                return value switch
                {
                    LogLevel.Trace => "00000000",
                    LogLevel.Debug => "00000001",
                    LogLevel.Information => "00000002",
                    LogLevel.Warning => "00000003",
                    LogLevel.Error => "00000004",
                    LogLevel.Critical => "00000005",
                    LogLevel.None => "00000006",
                    _ => null,
                };
            }

            if (format[0] is 'F' or 'f')
            {
                throw new NotSupportedException(@"Flags format is not supported.");
            }
        }

        throw new FormatException(@"Format string can be only ""G"", ""g"", ""X"", ""x"", ""F"", ""f"", ""D"" or ""d"".");
    }
}

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.