How to Localize Enums in C#

  Рет қаралды 9,539

Brian Lagunas

Brian Lagunas

Күн бұрын

Пікірлер: 91
@xVillani
@xVillani 3 жыл бұрын
Guys, remember to set the Access Modifier to internal in the Resources file. I spent more than a hour trying to figure out why i couldn't reference the resource file 😑😑😑 . It worked thankss a lot
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Great tip! Thanks for sharing
@shaihulud4515
@shaihulud4515 4 жыл бұрын
I am a pure hobbyist, and I can't tell how often I thought "I just quit, this is way above my head". Your vids could be a bit longer, but you break down things in an entertaining and yet comprehensive way. Thanks for letting me find new joy in my hobby Brian!
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you for the kind words. You really made my day.
@Tamer_Ali
@Tamer_Ali 4 жыл бұрын
Amazing video I hope you continue this video by telling us how to change the control/form direction when changing the culture. thanks
@BrianLagunas
@BrianLagunas 4 жыл бұрын
My next video will answer this question. I hope you like it.
@Tamer_Ali
@Tamer_Ali 4 жыл бұрын
@@BrianLagunas cannot wait
@mahmoudalaskalany
@mahmoudalaskalany 4 жыл бұрын
thanks man i just searched for this topic because i need it in a project and it was very helpful keep up the good work brian
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Glad I could help!
@ovimine7628
@ovimine7628 2 жыл бұрын
Thank you for this helpful video :) Question: If I do _Array StatusList = Enum.GetValues(typeof(Status));_ from _App.xaml.cs_ _OnStartup(...)_ I'm not getting the localized enum descriptions, any idea how to get the enum localized description when called from a C# code?
@solvedplus858
@solvedplus858 3 жыл бұрын
awesome , many thanks for your very valuable tutorial
@BrianLagunas
@BrianLagunas 3 жыл бұрын
Thanks for watching
@derschnurlich1512
@derschnurlich1512 4 жыл бұрын
Even after 15 years of C #, there is not a day where you don't learn something new. Thank you.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Me too! I am constantly learning something new everyday.
@gregersander9698
@gregersander9698 4 жыл бұрын
Thanks for your short videos. Right to the spot. I would like to know how to implement logging in a .net Core Prism best way. Should you use the ”built” in Microsoft dependency to implement? What’s the best way? Thanks
@BrianLagunas
@BrianLagunas 4 жыл бұрын
You can use any logger you want with Prism. It's rally a matter of preference. Just make sure you register the logging service with Prism, and you'll be good to go.
@AeromodeloRCBr
@AeromodeloRCBr 4 жыл бұрын
Interesting .... Thanks for sharing. Very good would be the use and ENUM using SQL database
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thanks for watching
@longuinni
@longuinni 4 жыл бұрын
That is nice!! Thanks for sharing Brian
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thanks for watching
@VinuP2023
@VinuP2023 4 жыл бұрын
Thank you Brian 😊 Tech question: When do we use dispose and finalize methods?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thanks for watching
@MikeOShay
@MikeOShay Жыл бұрын
I've been looking for the most efficient ways to do localization, and this is pretty promising! Any ideas if it could be simplified to avoid re-typing the name of each enum in each attribute? If the keys in the resx files correspond to the keys in the enum, it would be a lot more convenient to just get the name of the enum so we only have to type "[LocalizedDescription(typeof(EnumResources)]" for every entry, but maybe that isn't something the attribute is able to access.
@metaverse100
@metaverse100 4 жыл бұрын
Hi Brian, could you show us how to show version of program in dotnet core? In the old dotnet you could set automatic version number in assemblyinfo.cs with [assembly: AssemblyVersion("1.0.*")] but it is not available in dotnet core?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I could probably come up with something on versioning.
@ievheniiierokhin1677
@ievheniiierokhin1677 4 жыл бұрын
Awesome, thank you very much!!!
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Glad it helped!
@gajarubanjeyakumar7226
@gajarubanjeyakumar7226 4 жыл бұрын
@Brian Lagunas I wonder if you could do a video on expression trees? Dynamically subscribing to events using lambda expressions. I'm developing a scada application in wpf, i plan to develop some coustom controls like analog gauges. They need to subscribe to events (tag Value changed) They know the event name as a string only, which is a dependency property.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
That's a pretty advanced topic, and one I haven't touched in awhile. You can see the code that Prism uses to automatically subscribe to events using expression trees here: github.com/PrismLibrary/Prism/blob/master/src/Prism.Core/Commands/PropertyObserver.cs
@gajarubanjeyakumar7226
@gajarubanjeyakumar7226 4 жыл бұрын
@@BrianLagunas thanks, i will have a look. Maybe you can do it on your stream? :) I wish.....
@alexinaorsoni6251
@alexinaorsoni6251 4 жыл бұрын
Thank you Brian for this video. Something wired (or not, perhaps you could help me) : I followed your course and it doesn't work in my project. Description (localized or not) doesn't appear in my combobox but I have the name of enum. Besides, I used a binding for the selectedItem : to have the text of my selected item I have to use the type of my enum and not a string. Do you have an idea to use your tips in my case ? Thanks
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Hard to say without seeing the code.
@nandkishorsonwale
@nandkishorsonwale 4 жыл бұрын
Thanks for amazing video.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you for watching
@Tamer_Ali
@Tamer_Ali 4 жыл бұрын
Brian, could you add your other social media links to your KZbin channel's ABOUT tab like Twitch if you don't mind? I'd like to watch your awesome videos and streams and learn more from you.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thanks for the tip. I added some more links
@Tamer_Ali
@Tamer_Ali 4 жыл бұрын
@@BrianLagunas great 👍
@SkaptorOriginal
@SkaptorOriginal 4 жыл бұрын
Hey Brian! what about the selectedItem/selectedValue binding? can it be done as well?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Yes you can localize the SelectedItem of the combo as well. Most likely you'll just need a converter that reads the description attribute to get the localized text.
@mywildlifestories3793
@mywildlifestories3793 4 жыл бұрын
Hey Brian, is there any significant difference in usage of ivalueconverter and markupextension. Could you please elaborate more on these with example. When to use which?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
There's a big difference between the two. Are you asking specifically around the custom markup extension to bind to the enum?
@mywildlifestories3793
@mywildlifestories3793 4 жыл бұрын
@@BrianLagunas enums Or any other objects
@fredyjimenez4853
@fredyjimenez4853 4 жыл бұрын
Amazing video, thankss
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you
@zerologics5105
@zerologics5105 4 жыл бұрын
Thanks Brian!! Can you please make a video on how to make a multiple selection ComboBox?
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Hmmm... I'll have to think about the best way to keep something like that simple enough to do a video.
@omarbousbia6916
@omarbousbia6916 4 жыл бұрын
Thanks Brian, nice video. but i would like to ask more questions about binding to enums: how to bind a set of radio buttons/ checkboxes to an enum ???
@BrianLagunas
@BrianLagunas 4 жыл бұрын
There are a lot of ways to do this. I'll see if i can come up with an easy one that makes sense for a video.
@omarbousbia6916
@omarbousbia6916 4 жыл бұрын
@@BrianLagunas 👌
@harsheng
@harsheng 4 жыл бұрын
You are great👍
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thank you so much
@knowfaster
@knowfaster 4 жыл бұрын
How to communicate between ViewModels that opened in multi instance in MVVM
@BrianLagunas
@BrianLagunas 4 жыл бұрын
You just want to send messages between different viewmodels?
@knowfaster
@knowfaster 4 жыл бұрын
@@BrianLagunas yes, but to specific instance
@emilsandgren5290
@emilsandgren5290 4 жыл бұрын
Thank you for the video A question regarding using this in library code. Is there any other simpler way to use this converter than to write this: var statusValue = Status.Good; var statusDescription = new EnumDescriptionTypeConverter(typeof(Status)).ConvertTo(statusValue, typeof(string)).ToString();
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I believe you can just do `new EnumDescriptionTypeConverter(typeof(Status)).ConvertToString(statusValue);`
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Actually, I would just create an extension method to make it a single line of code public static string GetDescription(this Enum @enum) { return new EnumDescriptionTypeConverter(@enum.GetType()).ConvertToString(@enum); } Then all yo have to do is: var statusDescription = statusValue.GetDescription();
@MrTellus
@MrTellus 4 жыл бұрын
Nice. But your last comment made me lol - That's how EASY it is to localize your enums
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Well, it's easy now that you know how to do it 😁
@MrTellus
@MrTellus 4 жыл бұрын
@@BrianLagunas Sure 😉 For me the reflection part is the hardest to get right when coding.
@stasostrin47
@stasostrin47 4 жыл бұрын
Big thanks! )
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Thanks for watching
@yevheniytymchishin8401
@yevheniytymchishin8401 4 жыл бұрын
Ok, what if I have my localization service in the IoC container? Probably I am not able to use that in the attribute.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Sure you can. You just need to use a pattern like service locator so you can access the service in the attribute.
@yevheniytymchishin8401
@yevheniytymchishin8401 4 жыл бұрын
@@BrianLagunas Yeah, thanks. I guess I never used such approach yet.
@RebecaBagu-l2z
@RebecaBagu-l2z 11 ай бұрын
in 2024 still works :) Thankss a lot
@BrianLagunas
@BrianLagunas 11 ай бұрын
Awesome! Great to hear
@ShadowAimai
@ShadowAimai 2 жыл бұрын
Huh. I don't think I have ever thought of doing it this way. I usually have this kind of information in SQL, rather than it being hard coded.
@dksovfen
@dksovfen 4 жыл бұрын
Tech question: How can I generically do this: if (obj.GetType() == typeof(string)) { var result = SomeMethodReturningOrNeedsT(); }
@BrianLagunas
@BrianLagunas 4 жыл бұрын
Oh that's easy, not sure I should do a video, or just show you 😁
@dksovfen
@dksovfen 4 жыл бұрын
Brian Lagunas What ever floats your boat :) and thanks alot in advance
@BrianLagunas
@BrianLagunas 4 жыл бұрын
@@dksovfen Just use typeof(T) == typeof(string)
@dksovfen
@dksovfen 4 жыл бұрын
Brian Lagunas i mean the type is a variable but i need to parse it like this: method(); but that syntax doesnt work but how can i do this then without If and Else or switch alot of types. Also, im not in control of the method im just using it.
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I'm sorry, but I don't have the full context of what you are trying to do. Generics only work with known types. That's why every generic method should have a non-generic. Are you trying to check what type a method argument is?
@Nerin18
@Nerin18 Жыл бұрын
It would be nice if you share this project code. Despite your efforts, I failed to run this example.
@perahoky
@perahoky 4 жыл бұрын
How to localize WPF keyboard keys (KeyDown, KeyEventArgs, System.Windows.Input.Keys etc) to apply as display value on KeyGesture, KeyBinding for a keyboard shortcut control. Isnt quite easy..
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I'm not sure I understand the scenario exactly. You want to display a localized value for a key that has been pressed? Just get the localized value from the resource file using the key as the resource "name".
@jakubsuchybio
@jakubsuchybio 4 жыл бұрын
Why reflection, when there is couple of non-reflection solutions. Whyyyyyyy
@BrianLagunas
@BrianLagunas 4 жыл бұрын
This is just I how solved the problem. Would you mind sharing your couple of non-reflection solutions that allows the use of a long description with localization support and the ability to specify the resource file? One that I have used in the past was a IValueConverter, but I really dislike that approach as it was too limiting for my needs and required more code on the XAML side to function, which means other devs on the teams needed to know the details to make it work. You'd also have to write code in the converter to convert the localized value back into an enum which I really disliked. Over the years, I have found my approach best for the production apps I write. This also works across multiple platforms and is not specific to WPF. Write once, use everywhere.
@mikoo1991
@mikoo1991 4 жыл бұрын
plz no more c#. we want videos about web dev as requested earlier!
@BrianLagunas
@BrianLagunas 4 жыл бұрын
I record videos based on the questions I get. I don't get many questions about web. Asking for web videos is too broad for anything actionable.
How to Implement Two interfaces with Same Method Signature in C#
8:31
Which do I use, ConfigureAwait True or False?
6:53
Brian Lagunas
Рет қаралды 39 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
Adding Dynamic Properties: ExpandoObject vs DynamicObject
27:10
Brian Lagunas
Рет қаралды 19 М.
C# Flags Enum
12:35
Coding Tutorials
Рет қаралды 7 М.
ENUM vs Check Constraint vs Lookup Table: Which Is Better?
8:28
Database Star
Рет қаралды 1,8 М.
How to write "smarter" enums in C#
12:56
Nick Chapsas
Рет қаралды 135 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,6 МЛН
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 209 М.
Localize Dates, Currency, Numbers, and Text Direction in WPF
8:54
Brian Lagunas
Рет қаралды 3,8 М.
Delegates in C# - A practical demonstration, including Action and Func
1:09:11
How to Close Windows from a ViewModel in C#
10:39
Brian Lagunas
Рет қаралды 25 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН