Taswar Bhatti
The synonyms of software simplicity
Tag: C#
bom

Was detecting a file stream if it was Unicode encoded or not, so though I would share the code. Let say you an xml file that you need to detect if it has the Unicode BOM in the file. If you wish to know more about BOM look it up at wikipedia

Hope that […]

dotnet C#

C# Func vs. Action? What is the difference between a Func vs an Action in C#? The main difference is whether one wants the delegate to return a value or not. By using Func it will expect the delegate to return a value and Action for no value (void) 1. Func for methods that return […]

linq

Recently I was asked a simple code to improve the performance, and at first I couldn’t see it but as you know your brain starts working when you aren’t thinking of the problem anymore. (It happen to me when I was driving) Anyway the problem on hand was there is a for loop and when […]

linq

Here is some poorly written code that I had to review today and modify (i.e refactor). I have removed the domain of the code and renamed the variables, so that it remains anonymous, but the just of the code is still intact.

Lets go through the inner loop of the code first. First the […]

dotnet C#

Here is a quick way to detect if a text is in Canadian Aboriginal Syllabic in C#. It is just an extension method that would detect if your string is in that range by using regex.

Enjoy.

delegate

Here is a nice little code I did recently, where the Command Pattern is used with a notification observer like pattern. First of the Command Pattern, a simple interface for task with an execute method

Then the notification interface, with 2 methods, one when it started and one when its complete and the event […]

automapper

In this last part of the series I wanted to talk about how to register automapper at startup of your web application, in doing so it would help speed things up with automapper. There are many ways to do it, the easiest way is to just have a method inside Global.asax.cs file in your Application_Start […]

automapper

In this part I will show how we can use a customer value formatter (CustomFormatter) to format our mapped data into single “Number of Order:” and plural “Number of Orders:”. First the Domain and Dto (data transfer object)

Now we will introduce a CustomResolver and Formatter, for the Formatter we are inheriting from IValueFormatter […]

automapper

In Part 5, we will use a powerful feature that automapper allows us, which is CustomResolver. Lets look at our Domain Object which contains a boolean field called ShipToHomeAddress, what we will do is map those boolean to a string value with “Yes” or “No”.

For our mapping code we will introduce CustomResolver class […]

automapper

In Part 4 we will see how we can use projection to map inner objects for example a DateTime field. Again our domain and Dto (Data Transfer Object) looks like

We will map the PurchaseDate in the Domain Object to our Dto PurchaseHour and Purchase Minute.

As you can see the View now […]

UA-4524639-2