Welcome to SharpDevelop!

Thank you for choosing SharpDevelop as your development environment for .NET. SharpDevelop is a state of the art development enviroment, written from scratch using nothing but .NET itself - even the C# source code is available for you to have a look at it.

These are some of the main features of SharpDevelop:

  • Powerful project management via combines and projects
  • Syntax highlighting for many different programming languages
  • Integration with CVS for source code control
  • Code Completion for C#
  • Project support for many different languages, extensible for your needs

Please note that SharpDevelop is still a work in progress. Visit our Web site regularly to learn about updates, suggest features and inform us about problems you have encountered. Thank you, the SharpDevelop Team.

© 2001 IC#Code.com


Chapter Heading

Selecting a UI Language

SharpDevelop by default starts up with English as the user interface language. You can change this default preference by following the outlined procedure:

  1. In the Tools menu, select Options. This opens the Options dialog box shown below:
  2. To select a different language, move over the flag representing the language. Single-click on the icon, and your choice is reflected in "UI language set to:", which will appear below "Current UI language".
  3. Click OK to close the Options dialog box.
  4. Close SharpDevelop and re-open it (language changes are not reflected immediately, a restart is necessary)

Installing Language Packs

If after the release of SharpDevelop additional UI languages become available, these will be distributed via so-called language packs. Each language pack ships with a PDF document describing the installation procedure.


Selecting a Visual Style

You can switch the menu style of SharpDevelop to one of the following three options:

  • Visual Studio.NET menu style (default)
  • Office 2000 menu style
  • Standard Windows

To change the menu style, follow these simple steps:

  1. In the Tools menu, select Options. This opens the Options dialog box. Switch to the Menu Style option panel:
  2. The options are selected via a radio button group. Images next to the option show you the visual effect of your choice.
  3. Click OK to close the dialog box.
  4. Restart SharpDevelop for the changes to take effect.


[To be supplied]


Concepts of Unit Testing

Introduction

Unit tests are a valuable tool for all programmers, even if they don’t know it. Unit tests help to improve code reliability and stability. Therefore it cuts down the costs and time of 'classic' trial and error testing.

How to Test

To reduce the complexity of tests, each test should be independent of other tests - this avoids failings caused of unexpected side effects. Test cases should never be assumed to run in order.

One test method tests one or more methods of the production code. The ideal case is that you run tests on a per-method basis, because it makes it easier to pinpoint the method that fails. But this is sometimes not possible.

A test must verify the results automatically, instead of relying on manual verification of hard to read, Console.WriteLine statements. This allows any developer to run all tests without knowledge of the inner workings of the project and what has been tested. (If one test fails it is likely that he caused the failing and knows how to fix it, at least he could take back his changes). The developer only has to look deeper in the problem when a test method fails.

When to Write Tests

The developer should write unit tests while developing the production code. The XP people say that you should write tests before writing the production code, this can be funny too. (and surely has benefits)

When and How Often to Run Tests

  • Before and after refactoring a piece of code

  • Before starting to implement a new functionality

  • Each time a morale boost is needed


Walktrough: Unit Testing

Walkthrough: Unit Testing

Writing Unit Tests

For every class that you want to test, you have to write a "test suite", which is a class (eg *TestSuite) that inherits from TestCase. Define a static property Suite in this class, which returns a new ITest object (generally a TestSuite object). Now write the test methods - for standard's sake, they have Test in their names. (TestXyzTest). Add every method to the TestSuite object.

Example:

  1. using System;
  2. using TestingEnvironment.Framework;
  3.
  4. using SharpDevelop.Tool.Function;
  5.
  6. public class FileUtilityTestSuite : TestCase
  7. {
  8.
  9.     public FileUtilityTestSuite(string name) : base(name)
  10.     {
  11.     }
  12.
  13.     public void TestAbsoluteToRelativePathTest()
  14.     {
  15.         AssertEquals(@".\b", FileUtility.AbsoluteToRelativePath(@"C:\test\a", @"C:\test\a\b"));
  16.         AssertEquals(@"..\b", FileUtility.AbsoluteToRelativePath(@"C:\test\a", @"C:\test\b"));
  17.         AssertEquals(@"D:\b", FileUtility.AbsoluteToRelativePath(@"C:\test\a", @"D:\b"));
  18.         AssertEquals(@".\testme.exe", FileUtility.AbsoluteToRelativePath(@"C:\test\a", @"C:\test\a\testme.exe"));
  19.     }
  20.
  21.     public void TestRelativeToAbsolutePathTest()
  22.     {
  23.         AssertEquals(@"C:\test\a\b", FileUtility.RelativeToAbsolutePath(@"C:\test\a", @".\b"));
  24.         AssertEquals(@"C:\test\b", FileUtility.RelativeToAbsolutePath(@"C:\test\a", @"..\b"));
  25.         AssertEquals(@"D:\b", FileUtility.RelativeToAbsolutePath(@"C:\test\a", @"D:\b"));
  26.         AssertEquals(@"C:\test\a\testme.exe", FileUtility.RelativeToAbsolutePath(@"C:\test\a", @".\testme.exe"));
  27.     }
  28.
  29.     public static ITest Suite {
  30.         get {
  31.             TestSuite suite = new TestSuite("My 1st Testsuite");
  32.             suite.AddTest(new FileUtilityTestSuite("TestAbsoluteToRelativePathTest"));
  33.             suite.AddTest(new FileUtilityTestSuite("TestRelativeToAbsolutePathTest"));
  34.             return suite;
  35.         }
  36.     }
  37. }

How to start the test

First you have to reference the TestingEnvironment.dll found in the SharpDevelop bin directory to your testing project (you could include the test classes in your main project, but I prefer to have it external.)

And then compile the project.

Now you have to run the tests. To start the tests, select the "Run Tests" menu item in the context menu.

Then the test environment GUI pops up:

Click on the Run button to run the tests you choosen in the left treeview. You are informed of errors and failures. (btw. the bar turns red if an error occurs).

Compatibility

Generally SharpDevelop Test classes should be compatible to NUnit, as it was ported from JUnit too. Therefore you can look at the NUnit documentation for further information.


Walkthrough: Creating a File Wizard

Introduction

A file wizard creates user-configurable files on the fly (in contrast to File New templates). SharpDevelop allows to plugin custom file wizards which extend SharpDevelop. This walkthrough shows you how to create a custom file wizard.

Interfaces you should know

All file wizards have to implement this interface:

  1. namespace SharpDevelop.Internal.Templates {
  2.     public interface INewFileWizard
  3.     {
  4.         void StartWizard(Form mainWindow, INewFileCreator creator, string parameters);
  5.     }
  6. }

The mainWindow parameter is passed only for setting the Owner property of the wizard form correctly (and maybe for really advanced wizards to cast it to a MainWindow - and then gain full access to the SharpDevelop object model).

The second parameter is of interface type INewFileCreator:

  1. namespace SharpDevelop.Internal.Templates {
  2.     public interface INewFileCreator
  3.     {
  4.         bool IsFilenameAvailable(string fileName);
  5.         void SaveFile(string filename, string content, string languageName, bool showFile);
  6.     }
  7. }

The StartWizard method receives an INewFileCreator object. Currently it is used for "writing" a file to the IDE. The languageName parameter has to be set correctly according to the language name, or the syntax highlighting won't work correctly.

The parameters string is the "optional" string which can be defined in the wizard's definition Xml (described in the next section). Reasoning: you can use one assembly which creates VB, C#, JScript ... code and give a parameter in the Xml template which defines which language to generate by this parameter.

The File Wizard definition Xml

  1. <?xml version="1.0"?>
  2. <Template Originator="Mike Krueger" Language="C#" Created="3/09/2001" LastModified="3/09/2001">
  3. <TemplateConfiguration>
  4. <Name>Typed C# Collection</Name>
  5. <Icon>C#.File.CSFileIcon</Icon>
  6. <Category>C#</Category>
  7. <LanguageName>C#</LanguageName>
  8.   <Description>creates an typed C# collection</Description>
  9. <Wizard dll = "CodeGenerator.dll" class = "TypedCollectionGenerator.WizardWindow" parameters ="C#"/>
  10. </TemplateConfiguration>
  11. <TemplateFiles/>
  12. <FileOptions/>
  13. </Template>

As you can see, this is almost an ordinary file template xml. Except it does not define a template file and it has a Wizard tag in the TemplateConfiguration node. The Wizard tag must have the attributes dll and class - the parameters attribute is optional. The parameters are given to the INewFileWizard object which will be of the type class. (Therefore class must inherit from INewFileWizard).

Example File Wizard

You can find a sample file wizard in the "src\Wizards\file\TypedCollection" directory.


Walkthrough: Creating a Project Wizard

Introduction

A project wizard creates user configurable projects on the fly. SharpDevelop allows to plugin custom project wizards which extend SharpDevelop.

Interfaces you should know

All project wizards have to implement this interface :

  1. namespace SharpDevelop.Internal.Templates {
  2.     public interface INewProjectWizard
  3.     {
  4. void StartWizard(Form mainWindow, INewProjectCreator creator);
  5.     }
  6. }

The mainWindow is only for setting the Owner property correctly (and maybe for really advanced wizards to cast it to a MainWindow).

  1. public interface INewProjectCreator
  2. {
  3.     Combine Combine {
  4.         get;
  5.     }
  6.     bool IsFilenameAvailable(string fileName);
  7.     void SaveFile(IProject project, string filename, string content, bool showFile);
  8. }

The Project Wizard definition Xml

[To be supplied.]

Example Project Wizard

[To be supplied.]


Shortcut Keys

Clipboard Keys

Shortcut | Description
Ctrl+X, Shift+Del | Cut selection to clipboard
Ctrl+C, Ctrl+Ins | Copy selection to clipboard
Ctrl+V Shift+Ins | Paste selection from clipboard in text

Selection Keys

Shortcut | Description
Ctrl+A | Select whole buffer (file)

Completion Keys

Shortcut | Description
Ctrl+J | Template complete / Open template completion window

Miscellaneous Keys

Shortcut | Description
Ctrl+U | Reload buffer (file) from disk
Ctrl+I | Indent code section
Ctrl+B | Go to matching brace (if caret is over a bracket)
Ctrl+/ | Comment/Uncomment code section