Showing posts with label code samples. Show all posts
Showing posts with label code samples. Show all posts

Saturday, March 26, 2011

Visual Studio 2010 Tips and Tricks # 5 : Block Editing, Multi-line Coding

  • This is one of my favorite tricks in VS 2010 IDE. This one is more cool than my previous post [Visual Studio 2010 Tips and Tricks #4: Code Snippets ]
  • Did you know you can select any vertical area of your code by using “ALT” key and your “Mouse” in the Code area inside the editor.
  • Say we need to create Model class with lots of string variables and “Get”, “Set”. You can follow the tip#4 and use prop code snippet (or) you can use this Block Editing tip.

Editor_1

  • First select a vertical region of your code by pressing the “Alt” key and selecting a vertical line as shown above.

Editor_2

  • Start typing “public string” and see it fills in all the lines not just one line (as shown above).

Editor_3

  • Now press “Esc” to go out of this mode and start typing your Member names

Editor_4

  • Now again vertical select a region by pressing “Alt” key and use your mouse.

Editor_5

  • And enter “{ get; set; }” and your properties are done.

Editor_6

  • Yes but it looks ugly with lot of spaces in between, so use my previous tip [ Tip to autoformat code ] and select these lines and press “Ctrl + E + Ctrl F” to tidy up the code.

Editor_7

  • When there are lot of similar lines this approach is very helpful to code faster.
  • Say you want to convert all the properties from “public” to “internal”, this can be done very easily using our “Block” editing trick.
  • First use “ALT” key and select all the public word in all the lines.

Editor_8

  • Now start typing “internal” and you just renamed multiple lines. You may ask why not use “Quick Replace” but this is very helpful if you only want to apply the changes to only few lines and not the entire document.

Editor_9

  • This approach is very useful in situations say to enter comments for all lines, say to prefix “M_” or “_” to convert local variables to global etc..

Thursday, March 24, 2011

Visual Studio 2010 Tips and Tricks # 4 : Code Snippets

 

  • This is not a new feature, Code Snippets did exist in previous versions of Visual Studio.
  • Let us look at what are code snippets and how to use them.
  • Trust me they are very helpful for rapid application development. Ninja
  • Assume you are creating a class with member variables and basic getter, setter methods. Now you can sit and write the entire line for each member variable (or) you can make it rapid by following the steps shown below,
  • If you right click on your project and select “Add –> New Class –> enter class name”, it creates the class stub.
  • Now go in to the class and type “prop”

prop_1

 

  • A drop-down gets shown select “prop” and hit tab twice (tab-tab)
  • It will auto-fill the default datatype “int” and puts the “Get/Set” for you.

prop_2

  • Now if you want to change the datatype, click on “tab” and enter say “DateTime” on top of “int”.
  • And click another “tab” and type in your property name and that’s it you just wrote one member variable so fast Party smile

prop_3

 

  • Now having enjoyed rapid authoring, you may be wondering is there more auto-fill’s for most common syntax/structures.
  • Yes there is, for example, say you want to enter try catch. Just enter try and the dropdown shows available snippets,

prop_5

  • Select “try” and hit tab-tab

prop_4

  • Cool right you just saved yourself time entering the braces and aligning them etc..
  • Yes, so your next question is how do I know what all snippets are there, it is very easy,
  • Just right click on your code, select “Insert Snippet” or use short cut key “CTRL + K AND CTRL + X” to show the “Insert snippet” option.
  • Select the folder, say “Visual C#” and see all available snippet options, as shown below,

prop_6

  • Use lot of snippets while you are coding and increase your coding productivity. Nerd smile
  • Become a “Ninja Coder” Ninja
  • Stay tuned for my post about “how to create custom snippets”.

Thursday, May 24, 2007

Codeplex - Microsoft's answer for open source

I was amazed to see the list of open source microsoft projects available at code plex.

Some of the popular ones which we have been using like the Atlas and the Ajax extension sample controls are all from codeplex.
"CodePlex is Microsoft's open source project hosting web site. You can use CodePlex to create new projects to share with the world, join others who have already started their own projects, or use the applications on this site and provide feedback"



The license details are provided here,



Few projects which are very impressive are,


1) BlogEngine.Net - your own dot net blog engine

2) Scorm 2004 implementation for dot net

3) Sharepoint utilities

4) Sandcastle help file builder - for VS2005 IDE (very helpful)

5) Same Desk - brings desktop on the web (unlike silverlight i did not have to install anything to see those applications very impressive) snapshot attached below.

On SameDesk i open a calculator, was able to browse this blog and also search something on the map on the left hand side and the web page looks exactly like a desktop and the app looks like a windows application. :)
you can try this out here live - http://www.openspot.com/


Some implementations given above would take several months if teams were to start coding them from scratch and some i could not believe if it may be completed, but code plex gives the entire source code free.
Every dot net developer should check codeplex without fail.
Also there are server enterprise patterns & implementations.

Friday, November 17, 2006

More more more code samples :)

I remember the pepsi ad, "Yeh Dil Maange more!!" meaning, "this heart demands more" in Hindi (National language of India).

Similarly more code samples from .Net Framework 3.0

http://www.microsoft.com/downloads/details.aspx?FamilyID=22B58B6C-8F98-40D0-880D-C3339C5DA01E&displaylang=en&mg_id=10049

Overview
The Windows SDK samples for .NET Framework 3.0 include samples for .NET Framework 2.0, Windows Communication Foundation, Windows Presentation Foundation, Windows Workflow Foundation, and Cross Technology samples. These samples can be downloaded from here or are available when the Windows SDK is installed locally.

101 code samples for VS Dot net IDE 2005

One great thing about being and working in microsoft technologies is all that pampering you get via code samples, the videos, the code samples, if not there are usergroups and forums.

There is no need to break our heads for doing anything as some other person has already done something for you.

In that list, here is a list of 101 code samples for VS Dot net IDE 2005
http://msdn2.microsoft.com/en-us/vstudio/aa718334.aspx

Base Class Libraries - Group 1 Samples
The Base Class Library Group 1 samples show how to use the classes in the namespaces System.Net, System.RegEx, System.Transaction, System.Console and more. Samples include:

  • Changing ACL (Access Control Lists) on files
  • Console Enhancements including buffer control, simple animations and colors
  • Downloading files using FTP (File Transfer Protocol)
  • Network Programming including PING, UDP, and TCP network statistics
  • Using the new Stopwatch class to measure time
  • Compressing and decompressing files in the GZip format
  • Retrieving Drive Information
  • Using Generic Collections
  • Creating Regular Expressions to parse text

Base Class Libraries - Group 2 Samples
The Base Class Library Group 2 samples show how to use the new classes and methods in the namespaces System.Net.Cache, System.Runtime.InteropServices, System.Net.Sockets.Socket and more. Samples include:

  • Building a tracing infrastructure to track errors and application performance
  • Controlling cache policies with the new System.Net.Cache namespace
  • Creating a process viewer
  • Creating a Windows service manager
  • Using the data protection API
  • Encrypting and decrypting data
  • Using platform invoke to access legacy or unmanaged code from within managed code
  • Building in support for localization
  • Using the NGEN utility
  • Using the new SecureString class
  • Using new socket class methods
  • Using serial ports with the new Port class
  • Working with the file system
  • Working with threads to manage multiple tasks simultaneously
  • Building a simple web server with HTTPListener

Web Development Samples
The Web Development samples show how to use some of the new features of ASP.NET 2.0.

Windows Forms Samples
The Windows Forms samples show how to use some of the new functionality available to developers building desktop applications.

Visual Studio Tools for Office Samples
The Visual Studio Tools for Office (VSTO) samples show how to add functionality to Office applications like Word, Excel, InfoPath, and Outlook using the .NET framework and C# or Visual Basic.

Tablet PC Samples
The Tablet PC samples show how to create ink-enabled applications that utilize the power handwritten input with Tablet and Ultra Mobile Personal Computers.

.NET Compact Framework Samples
The .NET Compact Framework samples show how to use the new functionality found in Windows Mobile 5.0.