C#

JSON serializers benchmark updated – including MongoDB Driver

Just a quick note to say that I have updated the JSON serializers benchmark to use the latest Nuget versions of ServiceStack.Text, Json.Net and JsonFX. I have also included the JSON and BSON serializers from the MongoDB C# Driver in the test, and since BSON is a binary format I have included protobuf-net as a …

JSON serializers benchmark updated – including MongoDB Driver Read More »

C# – beware of async void in your code

In general, when you see async void in your code it’s bad news, because: you can’t wait for its completion (as mentioned in this post already) any unhandled exceptions will terminate your process (ouch!)   Suppose you have a timer event that fires every once in a while and you want to do some asynchronous …

C# – beware of async void in your code Read More »

F# – helper functions to convert between Async<unit> and Task

With the official release of .Net 4.5 and Visual Studio 2012, I suspect many .Net developers will be rushing to rewrite their data access or network layers (amongst many many other things!) to take advantage of the new async-await (see the excellent 101 examples here) language feature in C#, which means you’ll likely be working …

F# – helper functions to convert between Async<unit> and Task Read More »

F# – Make extension methods visible to C#

In F# you can write an extension method like this: Whilst this will work perfectly fine in your F# code, the extension method will not be visible to any C# code using the FileInfo type because F# and C# compiles extension methods differently. To make C#-compatible extension methods in F#, here’s what you need to …

F# – Make extension methods visible to C# Read More »

F# – defining explicit operator in F#

Update 2012/08/23: Thanks for the suggestion from Jizugu in the comments, I’ve updated the post to show you his approach to calling the explicit operator in a clean and elegant way.   In C#, you can define an explicit operator for your type using the explicit keyword: You can define an explicit operator like the …

F# – defining explicit operator in F# Read More »

Performance Test – Json Serializers Part III

Note: Don’t forget to check out Benchmarks page to see the latest round up of binary and JSON serializers. Following on from my previous test, I have now included JsonFx and as well as the Json.Net BSON serializer in the mix to see how they match up. The results (in milliseconds) as well as the …

Performance Test – Json Serializers Part III Read More »

Performance Test – String.Contains vs String.IndexOf vs Regex.IsMatch

To find out if a string contains a piece of substring, here are three simple ways of going about it in C#, just to name a few: String.Contains String.IndexOf where the return value is >= 0 Regex.IsMatch Out of curiosity I wanted to see if there was any noticeable difference in the performance of each …

Performance Test – String.Contains vs String.IndexOf vs Regex.IsMatch Read More »

Performance Test – Binary serializers Part III

Note: don’t forget to check out the Benchmarks page to see the latest round up of binary and JSON serializers.   Since my last round of benchmarks on binary serializers, there’s a new player in town – MessageShark, which at the time of this writing does not support serialization of fields, but offers comparable speed …

Performance Test – Binary serializers Part III Read More »

.Net Tips – use [field:NonSerialized] to stop serializing your event handlers

In C#, when you define an event in your class, e.g.: the event handlers will be serialized along with other properties, etc. This is because under the hood, the compiler translates your event into the following, as can be seen through JetBrain’s dotPeek decompiler: Since the generated EventHandler is not marked with the [NonSerialized] attribute …

.Net Tips – use [field:NonSerialized] to stop serializing your event handlers Read More »

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close