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

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

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

Type Argument Inference during Type Initialization

One of the least discussed topics about compiler and Generic Methods is its ability to infer the Type Arguments. For example, consider the following code. A typical invocation of the code might look like following. However, in some scenarios as above, the compiler is smart enough to allow you to skip the type argument from … Continue reading Type Argument Inference during Type Initialization

Revisting Anonymous Type

While classes and structs are extremely powerful, there are times when you want to escape the cermonies they require even for simplest of design. This is where anonymous types comes handy and has been so frequent used by the developers. So what are Anonymous types really ? Let's consider an example first. Anonymous Types are … Continue reading Revisting Anonymous Type

Json Custom Filtering : Remove Properties of a Type T

One of the recent questions that came up in SO which fascinated me was how do one filter a Json string by removing properties from Json, which is of a particular Type. For example, consider the following Json. What if you want to remove all Json Properties that has a value of Integer Type. What … Continue reading Json Custom Filtering : Remove Properties of a Type T