Hello Devz, JSON files are really common, we can see them everywhere. They provide a good structure to organize data, are simpler and lighter than XML files, and still human readable. In this simple example, we will show you how to use the Json.NET library (Newtonsoft) from NuGet. It is pretty simple to serialize and […]
C# – Copy a folder, its content and the sub-directories
Hello Devz, It’s unbelievable but yes, the System.IO provided by .NET doesn’t have a simple method to copy a folder, its content and the sub directories to another destination. There are a few different techniques to copy a directory with C#, using the command XCopy, or using a recursive method. The best one I saw […]
WPF – Animated Image
It is sometimes interesting to have an animated icon to tell to our user that their command is actually processing. Typically for a refresh icon. So, two solution: you could use an animated GIF and use an external library like WpfAnimatedGif (or the XAML MediaElement), or use an rounded icon (like this one) and create […]
WPF – Animated text
Sometimes it can be useful to have an animated text even in WPF. Typically a “Loading…”, where the 3 dots are moving one by one. Here is a simple way to do an animation with text: <StackPanel Orientation=”Horizontal” Margin=”20″> <Button Content=”Start” Height=”20″ Command=”{Binding StartCommand}” VerticalAlignment=”Top” Margin=”5″ /> <Button Content=”Stop” Height=”20″ Command=”{Binding StopCommand}” VerticalAlignment=”Top” Margin=”5″ /> […]
WPF – Nullable binding
Hello Devz, Imagine you have a TextBox binded to a nullable integer and you put a value in it. Now let’s say you delete this value. You expect to have your value to be null. To be able to do that, you need to update the properties of you binding like this: <TextBox Text=”{Binding Value, […]
C# – Simple email validation regex
Hello Devz, Do you have a web or WPF application that needs email address validation? Regex (regular expression) can help you. This post outlines a simple email validation regex that you can use straight away. What is a regex? A regular expression (regex for short) describes a search pattern using a particular text string. It’s […]
C# – Natural Comparer
We all had the issue with an OrderBy on a collection of String, having that kind of result: Test1 Test10 Test2 Test20 Test3 Instead of: Test1 Test2 Test3 Test10 Test20 Here is the solution: public class NaturalComparer : Comparer<string> { public override int Compare(string x, string y) { if (x == y) return 0; string[] […]
C# – Retry Pattern with Polly
Hello devz! Typically, we want to get data from a distant service. This service can be slow, could not respond, or just be down… But can we still be robust in our application? Using the Retry Pattern with Polly, you can! The Retry Pattern allows us to retry a task in case of exceptions, can […]
C# – DistinctBy extension
Hello devz, The Distinct extension from System.Linq is really useful but the DistinctBy a property is missing. So we will create our own DistinctBy extension. No worries, it’s really easy. What is DistinctBy? DistinctBy is a very simple extension snippet for C# which allows the developer to remove duplicated objects in a collection based on […]