Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Flag Enums are not supported #8

@michaelsw95

Description

@michaelsw95

Flag Enums produce an empty string when calling GetDisplayName(). It might be preferable if it produced a comma separated list in this case.

e.g. "Walk, Drive"

If we don't want to support it we could through an exception so this doesn't fail quietly.

using System;
using Enable.EnumDisplayName;

namespace ConsoleApp
{
    [Flags]
    public enum Commute
    {
        [EnumDisplayName("Cycle")]
        Bike = 1,
        [EnumDisplayName("Drive")]
        Car = 2,
        [EnumDisplayName("Walk")]
        Walk = 4
    }

    class Program
    {
        static void Main(string[] args)
        {
            var commuteWalk = Commute.Walk;

            Console.WriteLine(commuteWalk.GetDisplayName()); // "Walk"

            var commuteWalkDrive = Commute.Walk | Commute.Car;

            Console.WriteLine(commuteWalkDrive.GetDisplayName()); // ""
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions