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

How to get the friendly name of a Champion? #58

Open
selmaohneh opened this issue Jul 26, 2021 · 4 comments
Open

How to get the friendly name of a Champion? #58

selmaohneh opened this issue Jul 26, 2021 · 4 comments

Comments

@selmaohneh
Copy link

The extension method Champion.Name() as mentioned in the readme does not exist?
What is the desired way of accessing the display name of the Champion enum?

@selmaohneh
Copy link
Author

My humble try:

image

@MingweiSamuel
Copy link
Owner

Were you able to get the reflection working?

When we switched to enums proper @RyadaProductions suggested using attributes rather than the static-lookup based helper functions from before. Switching to enums was definitely the right choice, but looking at this now I feel the helper functions probably should've stuck around (and they're what I did in the Rust version of this library).

I'll probably add them back when I have a chance soon.

@selmaohneh
Copy link
Author

My quick sample does work, yes.

But it just shows the complexity needed without a helper method provided by Camille.

Whats the benefit of nesting the 'Descritpion' inside 'Display'? This breaks a lot of handy enum extensions like the ones from Enums.Net. Not nesting would make the retrieval of the description a one-liner.

Nevertheless: A helper method provided by Camille definitely is the best choice - I'm gonna leave that issue open as a reminder. :-)

Thanks in advance!

@RyadaProductions
Copy link
Contributor

Sorry for the late reply on this issue despite being pinged in it..

The reason for using the DisplayAttribute is because when making an interface that has a UI you might want to have a different name compared to the actual enum value. Random example MyEnum.Int with Display value being Integer
Some UI frameworks have support to get the Display value by default. IIRC WPF was one of them when dealing with certain controls.
The benefit of this is that it's not mutable during runtime. Since strings are by default mutable people could somehow adjust the string that is returned by accident I know it's unlikely but just for the sake of argument
We could add a helper function in the library for it to get the friendly name like @selmaohneh showed above here.
But to be honest I don't know the exact reasoning I had before, as we didn't document that from what I remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants