Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug - Enum with Flag attribute is not correctly handled #624

Closed
lucwuyts opened this issue Oct 21, 2020 · 6 comments
Closed

Possible bug - Enum with Flag attribute is not correctly handled #624

lucwuyts opened this issue Oct 21, 2020 · 6 comments
Assignees
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed. pre-discussed Pre-discussed and/or pre-collaborated with the reported todo Things to be done in the future

Comments

@lucwuyts
Copy link

The library does not handle Enums with the Flag attribute correctly.

I tried to solve this with an PropertyHandler, but when more than 1 flag is set, the input field in the Get function is null.
So the original enum is not passed to this function

@mikependon mikependon self-assigned this Oct 21, 2020
@mikependon mikependon added bug Something isn't working pre-discussed Pre-discussed and/or pre-collaborated with the reported todo Things to be done in the future labels Oct 21, 2020
@mikependon
Copy link
Owner

@lucwuyts - though I understand this problem, can you also specify some code to provide more context? Thanks

@lucwuyts
Copy link
Author

lucwuyts commented Oct 21, 2020

Consider this enum:

	[Flags]
	public enum Functie
	{
		Geen = 0x0000,
		
		Voorzitter = 0x0001,
		Secretaris = 0x0002,
		Penningmeester = 0x0004,

        Inst_Heli = 0x0008,
		Inst_Vliegtuig = 0x0010,
		
		Exam_Heli = 0x0020,
		Exam_Vliegtuig = 0x0040,
		
		Onderhoud_Veld = 0x0080,

        TerreinVerantwoordelijke = 0x0100,
		
        Vrijwilliger = 0x0200,

        VeiligheidsPiloot = 0x0400,

        OnderVoorzitter = 0x0800,        
}

When Functie has multiple flags, ToString() shows them concatenated with komma as separator.

Like this:

"Inst_Heli, Inst_Vliegtuig, Onderhoud_Veld, OnderVoorzitter"

I tried using this PropertyHandler:

    {
        public string Get(Functie input, ClassProperty property)
        {
            //Console.WriteLine($"Get {input}");
            return input.ToString();
        }

        public Functie Set(string input, ClassProperty property)
        {
            //Console.WriteLine($"Set {input}");
            var retval = Functie.Geen;
            if (!string.IsNullOrWhiteSpace(input))
            {
                var stukken = input.Split('|');
                foreach (var stuk in stukken)
                {
                    var deelFunctie = (Functie)Enum.Parse(typeof(Functie), stuk);
                    retval |= deelFunctie;
                }
            }
            return retval;
        }
    }

In the Set function, the string "input" is null when there is more than 1 option set.

@lucwuyts
Copy link
Author

Because the library doesn't work, i thought the parsing of such flag enum has to be done part per part, but this is not thrue.
Just this would suffice:

return Enum.Parse(typeof(Functie), input)

so above Set function is much too complicated, sorry about that. But the problem remains off course.

@mikependon mikependon pinned this issue Oct 27, 2020
@mikependon
Copy link
Owner

Upon further investigation, the Enum.GetName() method is failing to retrieved the value of the Enum if the Flags attribute is present.

[Flags]
public enum StorageType
{
    File = 1,
    Folder = 2,
    Directory = 4,
    Drive = 8,
    InternalStorage = 16,
    MemoryStorage = 32
}

And this one is always returning NULL as what RepoDB does.

image

@mikependon mikependon added the fixed The bug, issue, incident has been fixed. label Oct 27, 2020
@mikependon
Copy link
Owner

This is now deployed at RepoDB v1.12.5-beta1. Can you upgrade and test it there? Thanks

@mikependon mikependon added the deployed Feature or bug is deployed at the current release label Oct 28, 2020
@mikependon mikependon unpinned this issue Oct 28, 2020
@mikependon
Copy link
Owner

Closing this ticket now. Please do not hesitate to reopen or contact us ASAP if the issue is not fixed on your end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed. pre-discussed Pre-discussed and/or pre-collaborated with the reported todo Things to be done in the future
Projects
None yet
Development

No branches or pull requests

2 participants