March 26, 2008
OpenSocial
March 12, 2008
How Google keeps our information secure
February 19, 2008
ASP.NET Futures
download futures : http://www.asp.net/downloads/futures/
January 10, 2008
.Net 3.5 Extensions Part 2
In my previous post I have talk about "what is a method extension" and "how we can use that in our development". Let’s move into more detail.
Extension has change the way we design our applications. With previous versions of .net, which didn’t supports features like multiple inheritances, but with extensions we can design our applications to meet all those functionality. So here what I’m going to show is how we can program to interfaces using method extensions.
To start with we will take simple interface class scenario. We use interface to implement multiple features to a given class. Below is example of implementing multiple inheritances on a single class using interfaces.
public interface IFlyable {
void Fly();
}
Public interface IRunnable {
void Run();
}
Public interface ISwimming {
Void Swim();
Void BreatheInWater();
}
Public class Bird: IFlyable, IRunnable, ISwimming {
Public class Animal() {
}
Public void Fly() {
//Implement flying logic
}
Public void Run() {
//Implement Running Logic
}
Public void Swim() {
//Implement Swim Logic
}
Public void BreatheInWater() {
//Implement Breathe in water logic
}
}
What if there is a another class which needs to implement the same Swim logic in ISwimming, infact lets say all the classes which implement ISwimming has the same swim logic, but BreatheInWater logic is differs. How do we achieve this?
Public class Fish: ISwimming {
Public void Swim() {
//Implement same swim logic
}
Public void BreatheInWater() {
//Implement different Breathe in water logic
}
}
We could achieve this using some of the design patterns, but here I just wanted to show how easily we can do this using method extensions. Since Swim has the same logic in every class we can see as it’s a perfect method to use as an extensions. So we can implement the Swim logic in one place. To do that we need to remove the Swim method from ISwimming interface and place that in out method extension class as below.
//Implment the same swim logic
}
Note that we have this keyword before the ISwimming interface. This tells the compiler that ISwimming type has Swim method extension. So after implement the method extensions for the ISwimming interface we could modify the code as below.
public interface IFlyable {
void Fly();
}
Public interface IRunnable {
void Run();
}
Public interface ISwimming {
Void BreatheInWater();
}
Public class Bird: IFlyable, IRunnable, ISwimming {
Public class Animal() {
}
Public void Fly() {
//Implement flying logic
}
Public void Run() {
//Implement Running Logic
}
Public void BreatheInWater() {
//Implement Breathe in water logic
}
}
Public class Fish: ISwimming {
Public void BreatheInWater() {
//Implement different Breathe in water logic
}
}
Please note that we have removed the Swim method from the interface as well as from all the implementation classes. We only wrote the Swim method in our extensions class. This makes our code cleaner and easier to write. So when ever we create an object which implements ISwimming interface we get Swim method as an extension.
So here I covered how we can easily use Method extensions in our interfaces. Hope this helps!
December 18, 2007
.Net 3.5 Extensions Part 1
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
December 11, 2007
VS 2008
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
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
ASP.NET Training Videos
Well, this is for the developers whose unaware of these free training videos. Get them and learn...
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 26, 2007
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
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;
}
}