Rajesh kumar’s Blog

If you have knowledge, let others light their candles at it.

Archive for May, 2009

Visual Studio 2010 & .Net 4.0 Beta 1 download link

Posted by Rajesh Kumar on May 19, 2009

Hi All,

You can download the Visual Studio 2010 & .Net Framework 4.0 Beta 1 from the below link:

https://msdn.microsoft.com/en-us/subscriptions/securedownloads/default.aspx

Advertisements

Posted in .Net | Leave a Comment »

C# Code Snippets

Posted by Rajesh Kumar on May 14, 2009

 Hello All,

Visual Studio IDE provides some code snippets that reduces code typing. You can open the “Code Snippet Manager” from Visual Studio from the menu: Tools -> Code Snippet Manager.

I am giving the C# code snippets below for your quick understanding. 

Shortcut

Description

Snippet Code

#if

 

#if true

#endif

#region

 

#region MyRegion   

#endregion

~

Snippet for Class Destructor

~Class1()

{

}

Attribute

 

[global::System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]

sealed class MyAttribute : Attribute

{

    // See the attribute guidelines at

    // http://go.microsoft.com/fwlink/?LinkId=85236

    readonly string positionalString;

     // This is a positional argument

    public MyAttribute(string positionalString)

    {

         this.positionalString = positionalString;

          // TODO: Implement code here

         throw new NotImplementedException();

     }

      public string PositionalString

     {

         get { return positionalString; }

     }

      // This is a named argument

     public int NamedInt { get; set; }

}

checked

 

checked

{

}

class

 

class MyClass

{

}

ctor

 

public Class1()

{

}

cw

 

Console.WriteLine();

do

 

do

{

} while (true);

else

 

else

{

}

enum

 

enum MyEnum

{

}

equals

Overrides the “Equals” method

// override object.Equals

public override bool Equals(object obj)

{

    //       See the full list of guidelines at

    //  http://go.microsoft.com/fwlink/?LinkID=85237 

    // and also the guidance for operator== at

    // http://go.microsoft.com/fwlink/?LinkId=85238

    //

     if (obj == null || GetType() != obj.GetType())

    {

        return false;

    }

     // TODO: write your implementation of Equals() here

    throw new NotImplementedException();

    return base.Equals(obj);

}

 // override object.GetHashCode

public override int GetHashCode()

{

   // TODO: write your implementation of                       

           GetHashCode() here

   throw new NotImplementedException();

   return base.GetHashCode();

}

Exception

 

[global::System.Serializable]

public class MyException : Exception

{

    //

    // For guidelines regarding the creation of new exception types, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp

 

    public MyException() { }

    public MyException(string message) : base(message)

    { }

    public MyException(string message, Exception inner) : base (message, inner) { }

    protected MyException(              global::System.Runtime.Serialization.SerializationInfo
info,   global::System.Runtime.Serialization.StreamingContext
context): base(info, context) { }

}

for

 

for (int i = 0; i < length; i++)

{

}

foreach

 

foreach (var item in collection)

{

}

forr

 

for (int i = length – 1; i >= 0 ; i–)

{

}

if

 

if (true)

{

}

indexer

 

public object this[int index]

{

   get { /* return the specified index here */ }

   set { /* set the specified index to value here */ }

}

interface

 

interface IInterface

{

}

invoke

Safely invoke the event

EventHandler temp = MyEvent;

if (temp != null)

{

    temp();

}

iterator

 

public System.Collections.Generic.IEnumerator<ElementType>
GetEnumerator()

{

    throw new NotImplementedException();

    yield return default(ElementType);

}

Iterindex

Code snippet for named iterator/indexer
pair using nested class

public MyViewIterator MyView

{

    get

    {

         return new MyViewIterator(this);

    }

}

 

public class MyViewIterator

{

     readonly Class1 outer;

      internal MyViewIterator(Class1 outer)

     {

          this.outer = outer;

     }

 

     // TODO: provide an appropriate implementation here

     public int Length { get { return 1; } }

      public ElementType this[int index]

     {

         get

         {

            //

            // TODO: implement indexer here

            // you have full access to Class1 privates

            //

            throw new NotImplementedException();

            return default(ElementType);

         }

      }

 

      public System.Collections.Generic.IEnumerator<ElementType>
GetEnumerator()

      {

          for (int i = 0; i < this.Length; i++)

          {

              yield return this[i];

          }

      }

}

lock

 

lock (this)

{

}

mbox

 

global::System.Windows.Forms.MessageBox.Show(“Test”);

namespace

 

namespace MyNamespace

{

}

prop

 

public int MyProperty { get; set; }

propg

 

public int MyProperty { get; private set; }

sim

 

static int Main(string[] args)

{

   return 0;

}

struct

 

struct MyStruct

{

}

svm

 

static void Main(string[] args)

{

}

switch

 

switch (switch_on)

{

   default:

}

try

 

try

{            

}

catch (Exception)

{

    throw;

}

tryf

 

try

{            

}

finally

{

}

unchecked

 

unchecked

{

}

unsafe

 

unsafe

{

}

using

 

using(resource)

{

}

while

 

while (true)

{

}

 

Posted in .Net | 1 Comment »

Access Sessions from Silverlight and ASP.Net

Posted by Rajesh Kumar on May 12, 2009

Most of the web applications require maintaining session state with the help of various mechanisms. While working with Silverlight, we may need Add or Get data from ASP.Net session.

As the Silverlight works in client’s environment, it does not have direct access to ASP.Net session object. The only way we can retrieve the information from Session is through Web Service.

I have published an article in CodeProject with source code too at the below link: http://www.codeproject.com/KB/silverlight/SilverlightASPNetSessions.aspx

Posted in Silverlight | Leave a Comment »

Quickly Add XML Comments to Your Visual Studio Projects

Posted by Rajesh Kumar on May 8, 2009

Visual Studio gives us the flexibility to document the code with various types for XML comments. Visual Studio also provides a short cut “///” to get the default comment tags which does not include any default description as shown below:

Comment tags without description

Comment tags without description

Though it is okay, the developer needs to type a lot to fill the tags with the appropriate comments.

Would it not be a good idea to automate this too 🙂 ? If you are also looking for this kind of feature, do not resist yourself to visit “GhostDoc” tool.

GhostDoc is a free add-in for Visual Studio that automatically generates XML documentation comments for C#. Either by using existing documentation inherited from base classes or implemented interfaces, or by deducing comments from name and type of e.g. methods, properties or parameters.

You can download the GhostDoc for Visual Studio 2008 at:

http://www.roland-weigelt.de/ghostdoc/download08.php?version=2.1.3for2008

Once you extract the downloaded zip file, make sure to close all instances of “Visual Studio” and then double click on “GhostDoc2.1.3.msi” and install it.

After the installation, when you opened the Visual Studio for the first time, a GhostDoc setup screen will popup as given below:

HotKey Setup

HotKey Setup

Choose your required “HotKey” and then click on “Assign” button, then follow the next two screens (Create and Finish buttons).

Now, create or open any .Net project and type an empty method with some parameters. For this example, I have created and empty WebSite. When opened the Default.aspx.cs file, we can find Page_Load event.

 INSIDE the method or ON method name, right click the menu and choose “Document this” option as shown below:

Pre Document
Pre Document
Once you click on the above mentioned option, you can see the XML comments as given below:
Post Document

Post Document

Now you can clearly observe the difference and time saving between normal xml comments and GhostDoc features.
Hope you love to use it :).

Posted in .Net | 13 Comments »