December 18, 2007

.Net 3.5 Extensions Part 1

One of the promising features Microsoft released with .net 3.5 is "Extension Methods". As I'm planning to do a series of posts regarding the extensions, here I will start with a simple scenario. First let us see what is this "Extension Methods" is all about.

What is .Net 3.5 "Extension Methods" ?

Extension allow developers to add methods to the existing class/type without wrapping or extending it. It's allow developers to add new methods to an existing CLR type such as string,integer or ICloneable. It even gives the ability to add method implementation on interfaces which I'm planning to cover in my next post.

So let us take a simple scenario and will see how we used to do it.

Requirement is to validate a string to check whether it's a number.

Old way




So here StringHelper is a class where we used to write all our validation methods to an string. So when ever we want to validate we have to call the StringHelper class. Lets see how easy we can do this with extensions.

First you have to write a static class which includes all the validation required to string. I have written IsNumber method by passing the parameter as string. Note that there is this keyword before the type. By doing this we tell the compiler to add this method to the passing parameter type(in this case "string").






so, how do we call this method ? All we have to do is to call the method we wrote in the string variable we defined. You can see there is small blue arrow showing the method is "extension". You can see how easy is to add methods to the existing types without having to call another class to do the job.







You can even write methods with more parameters, below is a simple method which return the character in a string by passing another int parameter




So as we can see here, with extensions we can easily extend the exiting classes in CLR or even our own custom classes/interfaces. In my next post I will show you how we can use the extensions with interfaces. Hope this helps.

December 14, 2007

VS 2008 with Team Suite Edittion

Finally I have installed the Visual Studio 2008 Team Suite Edition. Well, I really haven't tried the VSTS 2005, but with VS 2008 I think yes, I'm going to try that out. I will post the stuff which I come across while exploring the VSTS 2008. Stay tuned.

December 11, 2007

VS 2008

Its been a while that I haven't blog about anything.... I was busy with the product that we're working on and we're behind the schedule. Anyhow since the technology moves on very quickly thought of grabbing them at the same pace.

Yesterday I installed the VS Web Developer express edition and played with some cool features in New C#. Method Extension was the best so far for me. I'm planning to do a series of articles on how we can use the Extensions to design & develop and how its effects on Multiple Inheritance.

September 24, 2007

Code Snippets

My Good old friend Prabath has just showed me the shortcut keys for the Code Snippets. I never tried code snippets before even though I knew its useful. I always prefer shortcuts keys when coding. I used macros most of the time, but now with some shortcut keys you can achieve the same task with code snippets.

How to generate a Property automatically using code snippets.
1. type prop and press the Tab key twice. And the Code for the Property will generate automatically. Use the Tab key to rename the variable names. Its that easy and simple.

links : http://www.codinghorror.com/blog/archives/000419.html

July 17, 2007

July 9, 2007

Optimizing ASP.NET 2.0 Web Project build performance

I found this very useful topic about ASP.NET 2.0 web project build performance. I notice that there are some issues with the ASP.NET 2.0 building, specially when there are too many folders in the project. This link will helps you to bring down your building time. Credit goes to Scott Guthari. http://weblogs.asp.net/scottgu/archive/2006/09/22/Tip_2F00_Trick_3A00_-Optimizing-ASP.NET-2.0-Web-Project-Build-Performance-with-VS-2005.aspx

July 3, 2007

Google Docs

Google docs now supports folder structures with nice looking UI. And one of the cool features in docs is if we needs to upload a document we can send that document to give address to upload the document.. i.e. Ludmal-dcjvpd4d-Ahfhrwx5@prod.writely.com (this email automatically generated from google doc). I found this real easy when ever I'm sending a document to the client I can BCC to this address and save all those documents in the centralized location. try your self. http://docs.google.com/

June 16, 2007

Ajax toolkit new release

Microsoft has release another version of its Ajax toolkit.. it includes really cool new controls like DropdowList, calendar control and more.. you can download and see the sample from the this location.. http://ajax.asp.net/ajaxtoolkit/

June 13, 2007

File Upload Control with Ajax update panel

FileUpload control in ASP.NET doesn't work properly on Ajax update control. It does nothing when we're try to upload a file. But you can fix that quickly just by adding a trigger to it.  check the below code...

   1:  <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
   2:                              <Triggers>
   3:                                  <asp:PostBackTrigger ControlID="Button1" />
   4:                              </Triggers>
   5:                              <ContentTemplate>
   6:                                  <asp:FileUpload ID="FileUpload1" runat="server" Width="275px" />
   7:                                  <asp:Button ID="Button1" runat="server"
   8:                                      Text="Upload" CssClass="FlatButton" OnClick="Button1_Click" />
   9:                              </ContentTemplate>
  10:                          </asp:UpdatePanel>

June 7, 2007

C# 3.0 - Automatic Properties

Creating loads of get,set to properties is always a pain. I had my own macro do that.. but with c# 3.0 automatic properties will take care of that. This will avoid us manually create private variables and assign them to get,set. The c# 3.0 compiler will create them automatically.
So the new Property code will look something like this..

public class Car {
public string CarModel {
get;
set;
}

public int MakeYear {
get;
set;
}
}

June 3, 2007

Web application project support in VS 2005

I thought that Web application projects doesn't exists in VS 2005, like it does in VS 2003. Well, im not quite right.... once you have installed VS 2005 SP1, you will get that feature in File & New Project. I like web application projects becoz its speed up the compilation and I can easily tier the application. you can download VS 2005 SP 1 here.

June 1, 2007

Microsoft Surface

Microsoft newest product, "Microsoft Surface".

http://www.microsoft.com/surface/

ref: http://weblogs.asp.net/scottgu/archive/2007/05/30/microsoft-surface-and-wpf.aspx

Writing IIS Host headers in C#

code for writing IIS host headers. You have to pass the host header value and the web site ID, and also you should provide the username and password.

public static void AddHostHeader(string hostHeader, string websiteID) {
DirectoryEntry site = new DirectoryEntry("IIS://localhost/w3svc/" + websiteID, "username", "password", AuthenticationTypes.None);
try {
PropertyValueCollection serverBindings = site.Properties["ServerBindings"];
serverBindings.Add(hostHeader);
Object[] newList = new Object[serverBindings.Count];

serverBindings.CopyTo(newList, 0);
site.Properties["ServerBindings"].Value = newList;
site.CommitChanges();
} catch (Exception e) {
throw e;
}
}

Google gears

need to search offline ?? try google gears..