Posts

Showing posts from June, 2017

Shuffle List in C#

Image
Yesterday, I was looking for an algorithm to shuffle a list of objects in C#. So in my mind, I started to think about "complex" algorithms to do that, using random numbers and list elements switching... I say "complex" because while I was googling, I found a good solution to do that ! And it takes only 1 line :p I would have never thinked of that :) :) Here is the cool code: var shuffledList = myObjectList.OrderBy(item => Guid.NewGuid()); So, that's really simple. You can use the "OrderBy()" Linq extension to rearrange the list. This method will take a 'random' object, in this case a GUID. And we know that GUIDs are 'unique' so, it does the job! You can use variants like this one: var rnd = new Random(); var shuffledList = myObjectList.OrderBy(rnd.Next()); Next step, compare performances, between different solutions...

Visual Studio for MAC, review (fr)

Image
If you are a developer, there are many chance that you already used Visual Studio, the famous Microsoft's IDE. Visual Studio for MAC is borned a few weeks ago . But is it a productive tool like on PC ? If you are a Xamarin Developer and never tried it, I suggest you to take a look at this short review to get some clues ! This review is avaible in french on mobilissime.fr : http://www.mobilissime.fr/index.php/2017/06/20/visual-studio-pour-mac-petite-revue-de-lide/

[Xamarin Forms] Custom bottom bordered entry (iOS & Android)

Image
Custom entry with renderers For my Xamarin Forms project I needed to render an 'Entry' control with a bottom border of a specific color. There are several possibilities but I will show you mine. For that, I used renderers. iOS one is particularly not trivial. The wished result look like that: iOS Renderer [assembly: ExportRenderer(typeof(ExtDatePicker), typeof(ExtDatePickerRenderer))] namespace MyCompany.iOS.Renderers { public class ExtDatePickerRenderer : DatePickerRenderer { protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e) { base.OnElementChanged(e); // Need to connect to Sizechanged event because first render time, Entry has no size (-1). if (e.NewElement != null) e.NewElement.SizeChanged += (obj, args) => { var xamEl = obj as DatePicker; if (xamEl == null) ret

[Xamarin Forms] build error: Unable to cast object of type 'Xamarin.Forms.Xaml.ElementNode' to type 'Xamarin.Forms.Xaml.ValueNode'

Image
Xaml build error For one of my Xamarin project, I just had this build error: This error was related to my XAML code : Unable to cast object of type 'Xamarin.Forms.Xaml.ElementNode' to type 'Xamarin.Forms.Xaml.ValueNode' After searching for a long 'moment', I just didn't understand what happened... My investigation (this process can help you :p) So I decided to remove a large part of my xaml code and then re-add it little by little. Each step I tried to compile to see when error occurs. So In my case, I determined that the piece of code that was going wrong was the following: Ok, it was my mistake but in the code editor, Visual Studio didn't tell me anything. I was trying to bind an event ( I though it was a property ) to a DateTime property... What is not possible. Hope this helps someone to save a few minutes :)