How to use Linq Lambda Expression IEqualityComparer For IEnumerable.Except

One of the thing that sometimes annoys is Lambda Expression with IEqualityComparer. I was trying to pick items with Except Comparer from the list. After doing quick search on google found the below extension method which can be used in such scenario. 

public static IEnumerable Except(this IEnumerable first, IEnumerable second, Func<TSource, TSource, bool> comparer)
{
return first.Where(x => second.Count(y => comparer(x, y)) == 0);
}

How to use:

List myItemsList = source.Except(myDeals, (x, y) => x.ID == y.ID).Take(requiredCount).ToList();

This will return the list of items except item(s) which match with an ID in myDeals. 

Error: Could not load file or assembly Ninject

Challenge:

Error: Could not load file or assembly ‘Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7’ or one of its dependencies. The system cannot find the file specified.

Above error started appearing suddenly in our local Sitecore (Sitecore.NET 8.1 (rev. 151207)) project. We eyed lot of articles on-line but none helped, So that is why I thought it’s better to blog this out. We investigated for couple of hours to get this fixed, may be this post saves someone’s time.

Read More

Using AutoMapper

Challenge:

We defined the Web-Service and were using it in an application. Web-Service returns an object or list of an object.

 

There was already code written to do the processing once we get the response object from web-service.But when we get the object via web-service, it append the Web Service Reference Name because of which we were not able to utilize the already written code for processing that object. We believe in Re-usability as much as possible and wanted to re-utilize that code which was also used by other functions. Web-Service was returning lot of data which includes list and list of object inside the list etc.

How to encode Trademark symbols ™ in C#

Hello Folks, Sorry was away for a while. As was very busy with Project.Challenge:
We were facing one strange issue with encoding Trademark symbol in C#. If you are also facing such similar issue then this post is for you.It was strange for us see that ™ isn’t encoding with HttpUtility.HttpEncode. As google is my best friend [so as yours], I tried to get the answer.Before we dig into the solution, I tried on following websites which help us to get the result live for the Http.HtmlEncode()http://htmlencode.org/
http://www.opinionatedgeek.com/dotnet/tools/htmlencode/encode.aspx

And we see that HTML Encode isn’t encoding ™.
Read More

How to escape line breaks while creating CSV or TSV file using C#

Hello C# friends.

Are you creating a CSV (Comma Separated Value) or TSV (Tab Separated Value) file in CSharp and you don’t know why your CSV file is breaking when you open it into Excel, then this post is for you.

Mr. Brian has written a very nice article on how to generate CSV file which we referred in our project.
http://www.csharptocsharp.com/generate-csv-from-generic-list

It was difficult to identify the problem. Values in object were html based and we were doing Html.Encode, so i thought that we need to do Html.Decode, but was unlucky.
To get better understanding of Html.Decode and Html.Encode refer: http://www.dotnetperls.com/httputility
Then thought that it can be  Encoding issue so tried to pass different encoding formats to StreamWriter but was unlucky in that too. I tried to identify in depth and reached to the problem and then solution.

Problem:
As my values were in Html format it were containing “t” or “n” or “r” which were creating an issue when writing a file using StreamWriter. As it get “t” or “n” or “r” it was breaking the file.

Read More