Taswar Bhatti
The synonyms of software simplicity
Tag: C#
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 […]

automapper

In this part we learn about Nested Mapping in Automapper and we will use the same OrderDto Object that we had previously but we will let Automapper to map the inner objects. Once again here is the Domain Objects First

The Dto (Data Transfer Object) look like

This time when we map Order […]

automapper

In this part I will be showing how Automapper uses flattening by convention. If we look at our OrderDto we will see that it has a IEnumerable of OrderItemsDto and also something called OrderNumber. This is the type of object we want to send to our presentation layer.

Compare that to our domain object […]

automapper

Recently I gave a talk on Automapper in Ottawa .Net Community, so I though I would post the main ideas of the presentation here also. The demo was based on an Order System where there were just 3 tables/classes, “Order”, “Customer” and “OrderItems” From the diagram we can see that a Customer has a Bio […]

linq

You are here beacause you probably got a Linq error, specifically Operator ‘==’ cannot be applied to operands of type ‘System.Collections.Generic.KeyValuePair‘ and ‘‘ So if you wish to do something like this to KeyValuePair using Linq

You will get this error Operator ‘!=’ cannot be applied to operands of type ‘System.Collections.Generic.KeyValuePair‘ and ‘‘ Since […]

serviceLocator

There are certainly many ways to stub out dependency, using constructor injection, etc etc. Here is one way to quickly stub out ServiceLocator rather than implementing ServiceLocatorStub. Lets say you have code that uses a helper and the dependency is not quite the responsibility of that object but its the sub object that uses it. […]

UA-4524639-2