One of the recent question in stackoverflow found interesting was about a Json, which needs to be deserialized to a Generic Class. What makes the question interesting was the Generic Property would have a different Json Property name depending on the type T. Consider the following Json This needs to be Deseriliazed to the following … Continue reading Deserialize Json to Generic Type
String or Array Converter : Json
Imagine you have a method which returns a Json String of following format. In order to deserialize the JSON, you could define a class as the following. This work flawlessly. But imagine a situation when your method could return either a single Language as seen the example above, but it could additionally return a json … Continue reading String or Array Converter : Json
Oxyplot : Selectable Point
While OxyPlot continues to be one of the attractive plotting library for .Net developers, there are times when you find longing for features that could make it even more better. One of such feature is ability to select/highlight a point in a series. While there is a Selectable Property with LineSeries, it doesn't quite let … Continue reading Oxyplot : Selectable Point
Revisiting Threads – Overhead of explicit threads
Recently I had the good fortune to read some of the invaluable books such as CLR via C# by Jeffery Rictcher, C# in Depth by John Skeet and Writing High Performance code in .Net by Ben Watson. It allowed me to revisit some of the basics on Threads and I thought to write down my … Continue reading Revisiting Threads – Overhead of explicit threads
Partitioner and Parallel Loops
Two common traps when using Parallel Loops could be summarized as following. * The amount of work done in the loop is not significantly larger than the amount of time spend in synchronizing any shared states. * Amount of work done is less than the cost of delegate or method invocation. Both of the problems … Continue reading Partitioner and Parallel Loops
SOLID : Liskov Substitution Principle (Part 2)
In the first part of the post, we visited the core definition of Liskov Substitution principle and took time to understand the problem using an example. In this second part, we would take time to understand some of the governing rules of the principle. The rules that needs to be followed for LSP compliance can … Continue reading SOLID : Liskov Substitution Principle (Part 2)
Conditional Serialization using NewtonSoft Json
One of the least explored feature of Newtonsoft Json is the ability serialize properties conditionally. Consider the hypothetical situation wherein you want to serialize a property in a class only if a condition is satisfied. For example, If the requirement is that you need to include serialize the Department Property only if the User Is … Continue reading Conditional Serialization using NewtonSoft Json
Serializing/Deserializing Dictionaries with Tuple as Key
Sometimes you run into things that might look trivial but it just do not work as expected. One such example is when you attempt to serialize/Deserialize a Dictionary with Tuples as the key. For example The above code would trow an JsonSerializationException when deserializing. But the good part is, the exception tells you exactly what … Continue reading Serializing/Deserializing Dictionaries with Tuple as Key
Evil Code #010 : Extension Methods
Back with Evil Code Series again. What would be the output of the following. The code attempts to prints 2 set of data, "SampleText" and Null Value. The PrintToString method, prints the output from the inbuild ToString() method, while the second method PrintToDescription, prints the output from an extension method. The extension method, as such, … Continue reading Evil Code #010 : Extension Methods
Json Recipies – Part 2
Continuing with our earlier post on Json Recipies, let's explore couple of quick reference recipes using the famous NewtonSoft.Json. Recipe 04: Deserialize to Anonymous Type One of the least explored feature in NewtonSoft is the ability to deserialize a Json to anonymous type. For example, This would produce an output as Isn't that quite useful. … Continue reading Json Recipies – Part 2