Thursday, August 19, 2010

Swaping on Refrence

C# does manipulate objects by reference, and all object variables are references. On the other hand, C# does not pass method arguments by reference; it passes them by value, (even if the method arguments are of reference type). Thus, a regular swap method will not work!
Let's come from the beginning, we know that there are four kinds of formal parameters in a C# method declaration, namely
  • Value parameters, which are declared without any modifiers. (default)
  • Reference parameters, which are declared with the ref modifier.
  • Output parameters, which are declared with the out modifier.
  • Parameter arrays, which are declared with the params modifier.
Thus if there is no any method parameter keyword (ref or out), the parameter can have a value associated with it. That value can be changed in the method, but that value will not be reflected when the control passes back to the calling procedure. This is true for all value types. Now, consider a reference type, an object. If we pass an object to a method and if the value of its member is changed, it will be retained even when the control is passed back to the calling procedure! This is because objects are manipulated by reference.

If so, then, if we pass two objects to a regular swap method and come back to the calling procedure to see whether they have got swapped, they would have not! Look down the code below,


public class SwapClass
    {
        public int x;
        public int y;
        public SwapClass(int xval, int yval)
        {
            x = xval;
            y = yval;
        }
    }
    public class Swaper
    {
        public static void SwapWithRef(ref SwapClass param1, ref SwapClass param2)
        {
            param1.y = 2000;
            param1.x = 1000;
            SwapClass temp = param1;
            param1 = param2;
            param2 = temp;
        }

        public static void SwapWithOutRef(SwapClass param1, SwapClass param2)
        {
            param1.y = 2000;
            param1.x = 1000;
            SwapClass temp = param1;
            param1 = param2;
            param2 = temp;
        }

      
    }

public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            SwapClass obj1 = new SwapClass(0, 0);
            SwapClass obj2 = new SwapClass(10, 20);
         
            Response.Write("
");
            Response.Write("
X1: " + obj1.x + " Y1: " + obj1.y);
            Response.Write("
X2: " + obj2.x + " Y2: " + obj2.y);
            Response.Write("
");
          
            Swaper.SwapWithOutRef(obj1, obj2);
            Response.Write("
After SwapWithOutRef");
            Response.Write("
X1: " + obj1.x + " Y1:" + obj1.y);
            Response.Write("
X2: " + obj2.x + " Y2:" + obj2.y);
            Response.Write("
");

            Response.Write("
After SwapWithRef");
            Swaper.SwapWithRef(ref obj1, ref obj2);
            Response.Write("
X1: " + obj1.x + " Y1:" + obj1.y);
            Response.Write("
X2: " + obj2.x + " Y2:" + obj2.y);
            Response.Write("
");
            Response.Write("---------------------------------");

            SwapClass obj3 = new SwapClass(0, 0);
            SwapClass obj4 = new SwapClass(100, 200);
            obj3.x = 10;
            obj3.y = 20;
            SwapClass temp = obj3;
            obj3 = obj4;
            obj4 = temp;

            Response.Write("
After Normal Swap Without passing the parameter towards a method");
            Response.Write("
X3: " + obj3.x + " Y3:" + obj3.y);
            Response.Write("
X4: " + obj4.x + " Y4:" + obj4.y);
            Response.Write("
");
        }
    }

Enjoy swapping

Tuesday, August 17, 2010

Classic Ajax Using the ActiveX object - XMLHTTP

The follwing code sipnet will gives an overview on the classic way of
 using the ajax call for getting the data from the webserver .

This is the way that we get the data from the web server .
In all the frameworklike the asp.net ajax,jquery Ext,.......are
make use of this.

The following activeX will only work with the IE, not in any other browser



function XmlHttpFunctionExample() {

    if(window.ActiveXObject) {

        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    }

    else {

        xmlhttp = new XMLHttpRequest();

    }

    xmlhttp.open("GET", "Time.aspx", true);

    xmlhttp.onreadystatechange = readyStateChangedHandler;

    xmlhttp.send();    

}


This is the function pointer that actually handles the response form the webserver


function readyStateChangedHandler() {

    if(xmlhttp.readyState == 4) {

        alert(xmlhttp.responseText);

    }    

}
Please see the previous post for the readyState/StatusCode used in web technologies.

Ajax Server Control to Control Multiline entry

In the Visual studio 2008 , we have option to create a Ajax Server Control which actually create a Client Side controls  ie on the java script.The only thing is that this requires a script managers on the page,without this these client side controls wont work because the all the stuff is made on the asp.net Ajax.

Following is a small code spinet for a custom control that is build on the Ajax Server Control.

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AjaxServerControl1
{
  
    public class ServerControl1 :TextBox,IScriptControl
    {
        private ScriptManager _scriptManager;

        private ScriptManager ScriptManager
        {
            get
            {
                if (_scriptManager == null)
                {
                    _scriptManager = ScriptManager.GetCurrent(Page);
                    if (_scriptManager == null)
                        throw new InvalidOperationException(String.Format("The control with ID '{0}' requires    ScriptManager on the page."+
                    "The ScriptManager must appear before any controls that need it.", ID));
                }
                return _scriptManager;
            }
        }

        public ServerControl1()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public  virtual IEnumerable GetScriptDescriptors()

        {

            ScriptControlDescriptor descriptor = new                                                                                                                       ScriptControlDescriptor("AjaxServerControl1.ClientControl1", this.ClientID);

            yield return descriptor;

        }

       

        public virtual IEnumerable GetScriptReferences()

        {

            yield return new ScriptReference("AjaxServerControl1.ClientControl1.js",                                                       this.GetType().Assembly.FullName);

        }



        protected override void OnPreRender(EventArgs e)

        {

            ScriptManager.RegisterScriptControl(this);

            base.OnPreRender(e);

           

        }



        protected override void Render(HtmlTextWriter writer)

        {

            writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, this.MaxLength.ToString());

            ScriptManager.RegisterScriptDescriptors(this);

            base.Render(writer);

        }



        

    }

} 


Here is the sample script the that will actually  do this ...................
/// <reference name="MicrosoftAjax.js"/>


Type.registerNamespace("AjaxServerControl1");

AjaxServerControl1.ClientControl1 = function(element) {
    AjaxServerControl1.ClientControl1.initializeBase(this, [element]);
    this.ctrl = element;
    this.ml = this.ctrl.getAttribute("maxlength");
}

AjaxServerControl1.ClientControl1.prototype = {
initialize: function() {
    
        AjaxServerControl1.ClientControl1.callBaseMethod(this, 'initialize');
        this.ctrl.attachEvent('onkeypress', this.createDelegate(this, this._keypress));
        this.ctrl.attachEvent('onpaste', this.createDelegate(this, this._paste));
        this.ctrl.MaxLength = this.ml;
        
    },
    _keypress: function(evt) {
    
        var select = document.selection.createRange();
        var len;        
        if (select.parentElement() === this.ctrl)
            len = this.ctrl.value.length - select.text.length;
        else
            len = this.ctrl.value.length;
        if (evt.keyCode === 13 && len == this.ctrl.MaxLength - 1 || len >= this.ctrl.MaxLength)
            evt.keyCode = '';
        delete len; delete select;
    },
    _paste: function(evt) {
    
        var data = new String(clipboardData.getData("text"));
        var select = document.selection.createRange();
        var len;
        if (select.parentElement() === this.ctrl)
            len = this.ctrl.value.length - select.text.length;
        else
            len = this.ctrl.value.length;
        len = len + data.length;
        if (len > this.ctrl.MaxLength) {
            if (evt.preventDefault) { evt.preventDefault(); }
            else if (window.event) { window.event.returnValue = false; }
        }
        delete data; delete select; delete len;
    },
    createDelegate: function(instance, method) {
    
        if (Function.createDelegate)
            return Function.createDelegate(instance, method);
        return function() { return method.apply(instance, arguments); }
    },
    dispose: function() {    
       
        AjaxServerControl1.ClientControl1.callBaseMethod(this, 'dispose');
    }
}
AjaxServerControl1.ClientControl1.registerClass('AjaxServerControl1.ClientControl1', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();



Now a small magic .Please see the previous post on the asp.net related to the tag mapping .

Enjoy coding

Monday, August 16, 2010

Methods, Delegates, Anonymous Delegates, and Lambda Expressions

Methods, Delegates, Anonymous Delegates, and Lambda Expressions


If we have a method declared as follows:

     static Int32 SomeMethod(Int32 input)
    {
            return input + 1;
    }


We can explicitly call it in a way every C# programmer should be familiar with:


    Int32 y = SomeMethod(5);
    Console.WriteLine(y);

Using a Delegate...

Now, we may want to wrap this call so we can execute it from somewhere else.
This is done through a delegate.

What's a delegate?

A delegate is an object instance  that "wraps" a method call (pretty much everything in the .NET framework in an object).
An easy way to think of it is as a reference to a method that we can pass around separately from the object
that "ownes" the method.  In order to "wrap" the method call, the delegate needs two things:

   1.      A reference to the instance of the object it will be calling the method on.
   2.      A reference to the method.


To create a delegate we first declare our delegate type.
We can think of this as being similar to declaring a new class:


       delegate Int32 SomeMethodDelegate(Int32 input);


And then we can use an instance of this delegate to "wrap" our method call:

Using the same method we had earlier...


    static Int32 SomeMethod(Int32 input)
    {
            return input + 1;
    }


Somewhere else in our code we can instantiate the delegate as follows.
(note: in the sample below, "Program" is a static class)


// f is a delegate object that "wraps" the call
SomeMethodDelegate f = new SomeMethodDelegate(Program.SomeMethod);

Now we can use our delegate instance to call the same method.


    Int32 y = f(5);


The compiler is smart enough to figure out which kind of delegate to instantiate 
so we can use a shorter syntax if we want. We are actually still very explicitly instantiating a delegate
by telling the compiler what kind of delegate we want with the declaration on the left hand side of the assignment operator.
(note: I don't need to specify the object in the following code sample because
the delegate instantiation is in the same class as "SomeMethod()".)


    // f is a delegate object that "wraps" the call
    SomeMethodDelegate f = SomeMethod;



Adding Generics in the Mix....

We may not need a bunch of explicit delegate types lying around in our project
(although sometimes it is good to have a few for more readable code) and can use generics to consolidate all delegates
with similar surface areas (the same input and output types):


    delegate TOutput GenericDelegate(TInput input);


Now we can wrap our method using our generic delegate just as before:

    // using generic delegate definition

    GenericDelegate f = SomeMethod;

    Int32 y = f(5);


Note: this GenericDelegate<>  is the same as the Func<> delegate defined in the 3.0 framework

    // using built-in Func<> generic delegate definition (3.0 framework)

    Func f = SomeMethod;

    Int32 y = f(5);


We also have the generic Action<> delegate which wraps a method with no return value and
a Predicate<> delegate which is usually used to perform tests returns a Boolean and
a Comparison<> delegate to compare two objects.

Anonymous Delegate....

We may want to have a method that does not belong to a class (which is why we call it anonymous)
and can declare it in-line using  the following syntax.  Notice how the method has no "outer shell" definition.
The "SomeMethodDelegate" object is still instantiated and points to the in-line method.


    // in-line method definition... it has no name so it is anonymous

    SomeMethodDelegate f = delegate(Int32 x) { return x + 1; };

    Int32 y = f(5);


We could use the same syntax to instantiate our anonymous delegate as well

    // in-line method definition... it has no name so it is anonymous

    Func f = delegate(Int32 x) { return x + 1; };

    Int32 y = f(5);


If you haven't done it already, it is worth taking some time and using the debugger to step
through code containing anonymous method to get a better understanding of how the execution of the code flows.

Closures...

One of the ultra-cool features of anonymous methods is that they support closures which is a concept
coming out of functional programming languages.  Closures are VERY powerful and can help us keep code more concise.
When a language supports closures it basically  means that the a method body has
access to any local variable declared outside it's scope.


    String hi = "Hello World";

    Action myAction = Console.WriteLine;

    Func myStringGetter = delegate()

    {

            // the variable "hi" is available here because

            // anonymous methods support closure

            return hi;

    };



    myAction(myStringGetter());


Lambda Expressions...

The syntax for declaring an anonymous delegate is pretty verbose (and kind of ugly). 
With the 3.5 Framework, we have a much shorter (and nicer) way to instantiate anonymous delegates using lambda expressions.
    SomeMethodDelegate f = x => { return x + 1;  };

    Int32 y = f(5);


The input parameter is the variable before the => symbol.
    x => { return x + 1;  };


The body of the method is what appear after the => symbol.

    x => { return x + 1;  };


Because the "SomeMethodDelegate" signature says we have to input a Int32 and output an Int32,
the compiler knows that our "x" variable should be an integer (see if makes more sense if you try and
match the delegate signature (below) up with our lambda expression (above).
delegate Int32 SomeMethodDelegate(Int32 input);


We can use an even shorter syntax for declaring simple anonymous methods with the lamba expression and
 leave off the brackets and the "return" keyword.  The following code uses the simpler syntax:
    // can use shorter syntax if you don't want brackets or "return" keyword

    SomeMethodDelegate f = x => x + 1;

    Int32 y = f(5);

    Console.WriteLine(y);


Of course we can use lambda expressions with generic delegates as well.  The following shows the lambda expression syntax
for instantiating a generic delegate with two input parameters.  If our delegate has multiple input parameters,
we must group them in parenthesis:
    Func add = (m, n) => m + n;

    Int32 y = add(3, 4);


What Are They Good For?

Delegates are used most frequently for subscribing to events
so we'll look at how we can utilize delegates with an object that exposes an event.

Here is our dummy event raising object which could just as easily be a UI form or control.

    class Broadcast

    {

            private event EventHandler m_somethingHappened;

            public event EventHandler SomethingHappened

            {

                add { m_somethingHappened += value; }

                remove { m_somethingHappened -= value; }

            }



            public void Fire()

            {

                if (null != m_somethingHappened)

                    m_somethingHappened(this, EventArgs.Empty);

            }

    }


Example 1:

Let's say we instantiate a new Broadcast object and want to wire up the events using anonymous delegates:

    Broadcast bc = new Broadcast();



    bc.SomethingHappened += delegate(Object sender, EventArgs args)

    {

            Console.WriteLine("Something Happened (anonymous method)");

    };



    bc.Fire();


Example 2:

We can also wire up our Broadcast object using a lambda expression:

    Broadcast bc = new Broadcast();

    bc.SomethingHappened += (snd, arg) => Console.WriteLine("Something Happened (Lambda)");

    bc.Fire();


Example 3:

There are also many other places where delegates can be useful.
Another scenario is when we need to pass a delegate to another method for execution.
See if you can figure out what's happening in the following code.

If we have a method declared that accepts a delegate and another item defined as its input parameters
it will execute the method using the second parameter as input.

    static TOutput ExecuteSomething(Func mthd, TInput input)

    {

            return mthd(input);

    }



    Console.WriteLine(ExecuteSomething(g => g - 5, 20));

Setting Margin for the Rich TextBox like controls

Setting Margin for the Rich TextBox like controls


.P
{
  MARGIN: 0in 0in 0pt
 }


If the set the above  margin then the space between the line will be diplayed as normal in the Rich TextBox type of controls such as a div with attribute  contenteditable="true"  At this point the div is editable and if we press a enter key then there will be additional space that will be generated .To a void this situation we can use the above CSS class.

Disable Selection On Webpages

onselectstart="return false;" style="user-select:none;-moz-user-select:none;"

if we have given like this then we can block the selection on a webpage
basically this will not allow a copy paste.

onselectstart="return false - is basically for the IE

;-moz-user-select:none - is for mozilla

and

user-select:none is the W3 standards which should follow in all the browsers  :)

Friday, August 13, 2010

using java.util.zip for Zipping the files

 The follwoing code snippet is to Zip multiple files into a single file using java.util.zip .


private void ZipFiles()
        {
           OpenFileDialog fd1 = new OpenFileDialog();
            fd1.Multiselect = true;
            
            if (fd1.ShowDialog() == DialogResult.OK)
            {
               SaveFileDialog sf1 = new SaveFileDialog();
               sf1.Filter = "ZIP Files|*.zip";
                //sf1.Filter = "RAR Files|*.rar";
                if (sf1.ShowDialog() == DialogResult.OK)
                {
                    
                    string zipFileName = sf1.FileName.ToString();
                    ZipOutputStream os = new ZipOutputStream(new java.io.FileOutputStream(zipFileName));
                    java.io.FileInputStream fs;

                    for (int i = 0; i < fd1.FileNames.Length; i++)
                    {
                        string[] arr = fd1.FileNames;

                        string sourceFileName = arr.ToString();
                       
                        string path = Path.GetFileNameWithoutExtension(sourceFileName);
                        string path2 = Path.GetFullPath(sourceFileName);
                        string path1 = Path.GetExtension(path2);
                        if (path1 == ".pdf")
                        {
                            ZipEntry ze = new ZipEntry(path + ".pdf");
                            ze.setMethod(ZipEntry.DEFLATED);
                            os.putNextEntry(ze);
                            //java.io.FileInputStream fs = new java.io.FileInputStream(str);
                            fs = new java.io.FileInputStream(sourceFileName);

                            sbyte[] buff = new sbyte[1024];
                            int n = 0;
                            while ((n = fs.read(buff, 0, buff.Length)) > 0)
                            {
                                os.write(buff, 0, n);

                            }
                            fs.close();
                        }
                        if (path1 == ".txt")
                        {
                            ZipEntry ze = new ZipEntry(path + ".txt");
                            ze.setMethod(ZipEntry.DEFLATED);
                            os.putNextEntry(ze);
                            //java.io.FileInputStream fs = new java.io.FileInputStream(str);
                            fs = new java.io.FileInputStream(sourceFileName);

                            sbyte[] buff = new sbyte[1024];
                            int n = 0;
                            while ((n = fs.read(buff, 0, buff.Length)) > 0)
                            {
                                os.write(buff, 0, n);

                            }
                            fs.close();
                        }
                        if (path1 == ".doc")
                        {
                            ZipEntry ze = new ZipEntry(path + ".doc");
                            ze.setMethod(ZipEntry.DEFLATED);
                            os.putNextEntry(ze);
                            //java.io.FileInputStream fs = new java.io.FileInputStream(str);
                            fs = new java.io.FileInputStream(sourceFileName);

                            sbyte[] buff = new sbyte[1024];
                            int n = 0;
                            while ((n = fs.read(buff, 0, buff.Length)) > 0)
                            {
                                os.write(buff, 0, n);

                            }
                            fs.close();
                        }
                        if (path1 == ".xls")
                        {
                            ZipEntry ze = new ZipEntry(path + ".xls");
                            ze.setMethod(ZipEntry.DEFLATED);
                            os.putNextEntry(ze);
                            //java.io.FileInputStream fs = new java.io.FileInputStream(str);
                            fs = new java.io.FileInputStream(sourceFileName);

                            sbyte[] buff = new sbyte[1024];
                            int n = 0;
                            while ((n = fs.read(buff, 0, buff.Length)) > 0)
                            {
                                os.write(buff, 0, n);

                            }
                            fs.close();
                        }
                    }

                    //fs.close();
                    os.closeEntry();
                    os.close();
                    // }

                    MessageBox.Show("Compression ok!");
                }
            }
            else
            {

            }

        }

Tag Mapping in ASP.NET


Tag Mapping in ASP.NET

 Tag mapping allows you to swap compatible controls at compile time on every page in your web application. A useful example is if you have a ASP.NET control, such as a TextBox, and you want to replace it with a customized control that is derived from TextBox. Instead of editing every web form and replacing the built in TextBox with your custom version, you can have ASP.NET in effect do it for you by modifying web.config:


<pages>

  <tagMapping>

    <clear />

    <add tagType="System.Web.UI.WebControls.TextBox" mappedTagType="TextBox"/>

  </tagMapping>

</pages>


When you run your application, ASP.NET will replace every instance of TextBox with CustomTextBox, which is derived from TextBox:


public class CustomTextBox : TextBox

{

    public CustomTextBox()

    {

    }



    // Control the multline length here 

}


In this way you can write the custom logic that controls the multiline length ie its not controled on version 2.0
The only thing that we need to remember is that when we do a tag mapping in the web.config file we need to derive form the WebControls ie there will always be a base class for the tag mapping .
Internally how it works is that when the asp.net creates/manulpulates the control,it actually check inside the web.config and picks the mapped controls

Thursday, August 12, 2010

Common Table Expressions

Using Common Table Expressions
A common table expression (CTE) can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query. Unlike a derived table, a CTE can be self-referencing and can be referenced multiple times in the same query.
A CTE can be used to:
  • Create a recursive query. For more information, see Recursive Queries Using Common Table Expressions.
  • Substitute for a view when the general use of a view is not required; that is, you do not have to store the definition in metadata.
  • Enable grouping by a column that is derived from a scalar subselect, or a function that is either not deterministic or has external access.
  • Reference the resulting table multiple times in the same statement.
Using a CTE offers the advantages of improved readability and ease in maintenance of complex queries. The query can be divided into separate, simple, logical building blocks. These simple blocks can then be used to build more complex, interim CTEs until the final result set is generated.
CTEs can be defined in user-defined routines, such as functions, stored procedures, triggers, or views.
Structure of a CTE 
A CTE is made up of an expression name representing the CTE, an optional column list, and a query defining the CTE. After a CTE is defined, it can be referenced like a table or view can in a SELECT, INSERT, UPDATE, or DELETE statement. A CTE can also be used in a CREATE VIEW statement as part of its defining SELECT statement. 
The basic syntax structure for a CTE is:

WITH expression_name [ ( column_name [,...n] ) ]
AS
( CTE_query_definition )
The list of column names is optional only if distinct names for all resulting columns are supplied in the query definition.
The statement to run the CTE is:
SELECT
FROM expression_name;

Example

 

The following example shows the components of the CTE structure: expression name, column list, and query. The CTE expression Sales_CTE has three columns (SalesPersonID, SalesOrderID, and OrderDate) and is defined as the total number of sales orders per year for each salesperson.

USE AdventureWorks2008R2;
GO
-- Define the CTE expression name and column list.
WITH Sales_CTE (SalesPersonID, SalesOrderID, SalesYear)
AS
-- Define the CTE query.
(
    SELECT SalesPersonID, SalesOrderID, YEAR(OrderDate) AS SalesYear
    FROM Sales.SalesOrderHeader
    WHERE SalesPersonID IS NOT NULL
)
-- Define the outer query referencing the CTE name.
SELECT SalesPersonID, COUNT(SalesOrderID) AS TotalSales, SalesYear
FROM Sales_CTE
GROUP BY SalesYear, SalesPersonID
ORDER BY SalesPersonID, SalesYear;
GO

Tuesday, August 10, 2010

Globalization of Resources

ASP.NET 2.0 has greatly improved the tools and functionality to create localized applications. One of the new key components is the introduction of a provider model for resource localization that makes it possible to use resources from sources other than ..Resx files.

We need to add the globalization tag inside the web.config like the following

 <globalization resourceProviderFactoryType="SLMemoryLeakSample.Web.Global.ResourceProviderFactoryExt" />

The next step is the  implement the abstract class ResourceProviderFactory as follows ...

     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Compilation;

    namespace SLMemoryLeakSample.Web.Global
    {
        public class ResourceProviderFactoryExt : ResourceProviderFactory
        {
            public override IResourceProvider CreateGlobalResourceProvider(string classKey)
            {
                //Here the ClassKey will be the TestLoaction 
                return new CustomResourceProvider();
            }

            public override IResourceProvider CreateLocalResourceProvider(string virtualPath)
            {
                throw new NotImplementedException();
            }
        }

        public class CustomResourceProvider : IResourceProvider
        {
            #region IResourceProvider Members

            Dictionary dictionary;

            public CustomResourceProvider()

            {

                dictionary = new Dictionary();

                dictionary.Add("lblName", "Name");

                dictionary.Add("lblAge", "Age");

            }

            public object GetObject(string resourceKey, System.Globalization.CultureInfo culture)

            {

                //Here the resourceKey will be the lblName 

                //From the CultureInfo we can get the culture.

                return dictionary[resourceKey];

            }



            public System.Resources.IResourceReader ResourceReader

            {

                get { throw new NotImplementedException(); }

            }



            #endregion

        }

    }



Inside the aspx page all that we have to do is the following 



 < asp:Label ID="Label1" runat="server"  Text="<%$Resources:TestLoaction, lblName%>" ></asp:Label>


that all ...........Wow .
This is post is for my friend abi

Wednesday, August 4, 2010

Constraints
When you define a generic class, you can apply restrictions to the kinds of
types that client code can use for type arguments when it instantiates your
class. If client code tries to instantiate your class by using a type that is
not allowed by a constraint, the result is a compile-time error. These
restrictions are called constraints. Constraints are specified by using the
where contextual keyword. The following
table lists the six types of constraints
Examples
Constraint Description

where T: struct

The type argument must be a value type. Any value type except
Nullable
can be specified. See
Using Nullable
Types (C# Programming Guide)
for more information.

where T : class

The type argument must be a reference type; this applies also to any class,
interface, delegate, or array type.

where T : new()

The type argument must have a public parameterless constructor. When used
together with other constraints, the new()
constraint must be specified last.

where T : <base class name>

The type argument must be or derive from the specified base class.

where T : <interface name>

The type argument must be or implement the specified interface. Multiple
interface constraints can be specified. The constraining interface can also be
generic.

where T : U

The type argument supplied for T must be or derive from the argument supplied
for