.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

The Decorator Pattern & Extension Methods

Posted By: Venkat     Posted Date: February 03, 2010    Points: 2   Category :Patten/Practices
Numerous design patterns exist in the software world today, and ultimately nothing is preventing you from making your own (if people buy into it or not is another question). Furthermore, there is no 'master list' of patterns that all developers agree upon. While this is true, if you pick up any book on the subject, you will find a set of very common patterns most programmers agree are very useful. Many of these patterns were first formalized in the seminal book on the subject, Design Patterns: Elements of Reusable Object-Oriented Software (aka, the Gang of Four [GOF] book; not to be confused with the UK punk band of the same name).

View Complete Post

More Related Resource Links

The Decorator Pattern & Extension Methods

The decorator pattern provides a formal way to add new functionality to an existing type, without sub-classing. First question: What is wrong with classical inheritance? In and of itself, nothing is wrong with the good old Is-A relationship. It is very common to derive a new class from an existing base class in order to override a few virtual members, and add a pinch of new functionality.

Basic Instincts: Extension Methods


This column discusses one of the new features of Visual Basic 2008-Extension Methods. This powerful new feature was introduced to support LINQ. See what extension methods are, how to apply them yourself, and get some great usage tips.

Adrian Spotty Bowles

MSDN Magazine November 2007

Extension methods and viewstate


Hi all,

I am creating 2 extension methods for a textbox, which need to store a value and get the value, same like property, unfortunately dotnet 3.5 doesnt support extension property, so created two extension method for set and get, I am so confusing where should I store the value, like session, cache or anything else, but my recommendation to store in the viewstate object. how can I store value to viewstate. 

example my code look like

public static class clsExt
    public static bool getValue(this TextBox tb)

        return (bool)Viewstate[tb.ID];

    public static void setValue(this TextBox tb, bool value)

        Viewstate[tb.ID] = value;


Its not good idea to store session or cache, bcoz its should store only in the pagelevel, how can do this? How other textbox property storing? Could any one help on this issue please?

Thanks in advance.

Creating HTML Helpers with Extension Methods


namespace MvcLogin_Validation.Helpers
    public static class LabelExtensions
        public static string Label(this HtmlHelper helper, string target, string text)
            return String.Format("<label for='{0}'>{1}</label>", target, text);



Above is my html helper class.

<%= Html.Label("first name", "First name") %>

This is how I use it.

Now while using it I am getting an error which says, "  No overload for method 'Label' takes '2' arguments ", where as this link ( http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs) says to do it exactly as i did.

Can anyone please guide where I am going wrong.



what is Extension Methods and when, where we will we use it


what is Extension Methods and when, where we will we use it

interesting problem about @ and extension methods.


Note , that i'm new to c# so it might not be a problem.

first , what is the exact meaning of @ in Razor ?

does it mean WebPage.Response.Write ?

next, i designed an extension method to WebPage ( by the way that is the coolest feature ever in c# )

in my Razor code , to use it in a webpage , i must write @this.MyExtensionMethod() instead of @MyExtensionMethod().

So why is it?  because @this.MyExtensionMethod() and @MyExtensionMethod() should be the same ?

here is my extension method :

using System;
using System.Web;
using System.Web.WebPages;

namespace MyExtenstionMethods{

	public static class Utility{

	    // make the page to render optional
		public static dynamic RenderOptionalPage(this WebPage Webpage ,string page="",params object[] data){

				return Webpage.RenderPage(page,data);
            }catch(HttpException ex){
                return new HtmlString("<!-- page not found -->");


Matching C# methods with a pattern finding the Public, Private, etc modifiers and balancing the curl


Hello all,

For a large conversion project, we need to match certain key words within C# methods and remove the entire method if found. I know .Net has a feature that allows balanced matching on the curly braces, but I am not sure how to implement it.

In a two step process, you could match the modifiers Public, Private, etc and their balanced curly braces to identify the methods and then remove those that contained the key words. In a one step process, I think you could use a positive lookahead for the key words as well.

Could someone help me with the pattern that has the balanced curly brace logic with the modifiers to identify the methods? Thanks in advance for any ideas and/or suggestions.


Have a great day!

Extension Methods

Extension methods enable you to “add” methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type. (Source MSDN)

Dialogs and ViewModel - Using Tasks as a Pattern

The ViewModel/MVVM pattern continues to gain popularity, with a blog post showing up every so often, and with tweets and retweets popping up even more often :-). At the same time, there are some interesting topics beyond the core pattern that continue to fuel experimentation. A big one amongst those is how should applications use dialogs when using the view model pattern.

The crux of the problem is the desire to keep the view model independent of UI concerns, and ensure it can be tested in a standalone manner, but that often comes to odds when you want the view model to launch a dialog, and/or do some work after the dialog is closed.

Prototype Design Pattern in C#. Vb.NET

Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype

Adapter Design Pattern in C#, VB.NET

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Singleton Design Pattern in C#, Vb.NET

Ensure a class has only one instance and provide a global point of access to it.

Implementing Continuous Scrolling UI Pattern in ASP.NET

When you have numerous records to show, we have to resort to Paging. There is a better alternative to display voluminous data (especially read only data) while providing a better user experience & also making efficient use of server bandwidth - the Continuous Scrolling or Infinite Scrolling UI Pattern. Read on to know more about how to implement Continuous Scrolling UI Pattern in ASP.NET with a GridView.

Using jQuery to directly call ASP.NET AJAX page methods

Here I am looking to explain how to call page methods using jQuery. Using jQuery to directly call ASP.NET AJAX page methods

Factory Pattern in asp.net

The job of the Factory design pattern is to create concrete sub classes. You can see the Factory design pattern used throughout the .NET Framework.

The essence of the Factory Pattern is to "Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses." Factory methods encapsulate the creation of objects. This can be useful if the creation process is very complex, for example if it depends on settings in configuration files or on user input.

Singleton Design Pattern in Asp.net using C#

When we want to make a only one instance of a class and also making sure that there is a global access point to that object then the design pattern we user is called Singleton. The pattern ensures that the class is instantiated only once and that all requests are directed to that one and only object.

The Factory Design Pattern

Software architects generally think in terms of high-level abstractions rather than low-level programming details. Representing a system in terms of high-level abstractions promotes understanding of the system and reduces its perceived complexity. One such set of abstractions is software design patterns. They have been successfully applied in the past to simplify and solve recurring problems in software design.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend