CSharpTest.Net
AddHandler(Type) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Commands Namespace > CommandInterpreter Class > AddHandler Method : AddHandler(Type) Method

targetObject

Glossary Item Box

Adds the static methods to the command list, and static properties to the list of global options (used with commands set/get)

Syntax

Visual Basic (Declaration) 
Public Overloads Sub AddHandler( _
   ByVal targetObject As Type _
) 
C# 
public void AddHandler( 
   Type targetObject
)

Parameters

targetObject

Example

Library/Library.Test/TestCmdInterpreter.cs

C#Copy Code
CommandInterpreter ci = new CommandInterpreter(DefaultCommands.None, new TestCommands());
Assert.AreEqual(2, ci.Options.Length);
Assert.AreEqual("Other", ci.Options[0].DisplayName);
Assert.AreEqual("SomeData", ci.Options[1].DisplayName);

Assert.AreEqual(4, ci.Commands.Length);
Assert.AreEqual("BlowUp", ci.Commands[0].DisplayName);
Assert.AreEqual("Count", ci.Commands[1].DisplayName); // <= alpha-sorted
Assert.AreEqual("ForXtoYbyZ", ci.Commands[2].DisplayName);
Assert.AreEqual("Hidden", ci.Commands[3].DisplayName);

foreach (ICommand c in ci.Commands)
    ci.RemoveCommand(c);
Assert.AreEqual(0, ci.Commands.Length);

ci = new CommandInterpreter(DefaultCommands.None);
Assert.AreEqual(0, ci.Options.Length);
Assert.AreEqual(0, ci.Commands.Length);

ci.AddHandler(typeof(StaticTestFilter));
Assert.AreEqual(0, ci.Options.Length); // the type StaticTestFilter contains filters and no commands/options
Assert.AreEqual(0, ci.Commands.Length);

ci.AddHandler(new TestCommands());
Assert.AreEqual(2, ci.Options.Length);
Assert.AreEqual(4, ci.Commands.Length);
VB.NETCopy Code
Dim ci As New CommandInterpreter(DefaultCommands.None, New TestCommands())
Assert.AreEqual(2, ci.Options.Length)
Assert.AreEqual("Other", ci.Options(0).DisplayName)
Assert.AreEqual("SomeData", ci.Options(1).DisplayName)

Assert.AreEqual(4, ci.Commands.Length)
Assert.AreEqual("BlowUp", ci.Commands(0).DisplayName)
Assert.AreEqual("Count", ci.Commands(1).DisplayName)
' <= alpha-sorted
Assert.AreEqual("ForXtoYbyZ", ci.Commands(2).DisplayName)
Assert.AreEqual("Hidden", ci.Commands(3).DisplayName)

For Each c As ICommand In ci.Commands
    ci.RemoveCommand(c)
Next
Assert.AreEqual(0, ci.Commands.Length)

ci = New CommandInterpreter(DefaultCommands.None)
Assert.AreEqual(0, ci.Options.Length)
Assert.AreEqual(0, ci.Commands.Length)

ci.[AddHandler](GetType(StaticTestFilter))
Assert.AreEqual(0, ci.Options.Length)
' the type StaticTestFilter contains filters and no commands/options
Assert.AreEqual(0, ci.Commands.Length)

ci.[AddHandler](New TestCommands())
Assert.AreEqual(2, ci.Options.Length)
Assert.AreEqual(4, ci.Commands.Length)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys