Posts
An Article on Unit Testing Events in C# 3.0
Please read this article to find out an interesting way to write unit tests on your events.
http://www.dotnettoad.com/index.php?/archives/12-unit-testing-events.html
Unit testing has always seemed rather easy and annoying to most of the people who are new to test driven development for the reason because there is not much room for coding other than the Assert methods. Yet, I have found that people actually starts finding it cool once they have written some test codes and stuck at a point where it offers the 'Challenge' to really write a clean and concise test code.
Posts
How To Set Default Application Wide CommandTimeout in LINQ to SQL DataContext Subclasses
Sometimes you have written long running stored procedures and you need to invoke the stored procedures through your LINQ to SQL class. By default the SqlCommand has a timeout value of 30 seconds and in some instances you may need a longer value to complete your long running database operations. In a situation like this, if you are using the default time out value, you may encounter the following exception scenario,
Posts
string.GetValueOrDefault() - A Simple Extension Method
I have found that, I have written codes like the following one in my projects before now at some places.
string myString = someString == null ? string.Empty : someString;
However, with the advent of extension methods in C# 3.0 (.Net 3.5), I have a better way of achieving this goal in my projects. So, I just wrote an extension method as the following one-
public static class StringExtensions { public static string GetValueOrDefault(this string instance) { return instance == null ?
Posts
Best of Today's RSS from My Daily Feeds
1. If using LINQ gives you a great feeling, then I suggest you to read this post (to make it feel even better) where you learn about a less used keyword called 'let' to make your LINQ queries more readable and human friendly.
http://www.codethinked.com/post/2008/04/The-Linq-quot3bletquot3b-keyword.aspx
Posts
IsNullOrEmpty() - A Handy Extension Method for IEnumerable<T>
Many a time when you are just about to write a foreach loop on your IEnumerable<T> object you need to check whether the object is null or empty in the following manner
if(myEnumerable != null || myEnumerable.Count() > 0) { foreach(<type> item in myEnumerable) { ... } } However, with the advent of Extension methods, you can write one custom extension method like the following -
public static class IEnumerableExtensions { public static bool IsNullOrEmpty<T>(this IEnumerable<T> instance) where T : class { return instance == null || instance.
Posts
My Today's best RSS feeds
1. Well, we have a CI in place and we are also very excited to see a new notification message coming to our email inbox on a commit from our team members. CruiseControl.Net really made is fun and so easy to be really continuously integrating our projects.
However, I didn't know of this cool feature until I read this article. I suggest you all CruiseControl.Net cruisers to take a look -
Posts
Best RSS Feed I have read today
Many a times, if feels great to know about the online users and some more details about them when they are on your website. This article gives you the code example to achieve this in your ASP.Net application.
http://www.aspdotnetfaq.com/Faq/How-to-get-detailed-info-about-all-online-visitors-that-are-currently-browsing-your-ASP-NET-website.aspx
Posts
Posts of the day that I liked most
1. The Monostate Pattern - Another way to look into Singleton and some improvement over singleton issues.
Read it Here
2. Another good article on LINQ regarding the grouping queries. Read it Here
Posts
Creating Instances of internal classes using Spring.Net
Creating an instance of an internal class using Spring.Net is a little tricky. I know that, you can achieve this by adding an InternalsVisibleTo attribute to your assembly. However, the following solution also works as desired.
Say, you have an namespace named SampleClasses that contains the a public interface named 'IPublicInterface' and also an internal class named 'InternalClass' that implements the IPublicInterface interface and looks like the following - 1: namespace SampleClasses
Posts
Logging the LINQ to SQL Generated SQL Queries/Commands
I was looking for logging solutions for the generated SQL in one of my projects where I am using LINQ to SQL. I found that sometimes the the Exceptions and StackTrace information does not say much about what's really causing the problem with LINQ to SQL queries/commands.
To see the actual SQL that's generated from LINQ you may write a code like the following-
SampleDataContext context = new SampleDataContext(); //You may wish to use any subclass of System.