CSharpTest.Net
CommandAttribute Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Commands Namespace : CommandAttribute Class

Glossary Item Box

Provides all the properties available for a command.

Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Class CommandAttribute 
   Inherits DisplayInfoAttribute
   Implements IDisplayInfo 
C# 
[SerializableAttribute()]
public class CommandAttribute : DisplayInfoAttribute, IDisplayInfo  

Example

Library/Library.Test/TestCmdInterpreter.cs

C#Copy Code
CommandInterpreter ci = new CommandInterpreter(new TestCommands());

IOption option = ci.Options[0];

//[Option("Other")]
Assert.AreEqual("Other", option.DisplayName);
Assert.AreEqual(typeof(int), option.Type);
//[AliasName("alias")]
//[System.ComponentModel.DisplayName("ingored-due-to-OptionAttribute")]
Assert.AreEqual(2, option.AllNames.Length);
Assert.IsTrue(new List<string>(option.AllNames).Contains("Other"));
Assert.IsTrue(new List<string>(option.AllNames).Contains("alias"));
//[System.ComponentModel.Description("description")]
Assert.AreEqual("description", option.Description);
//[System.ComponentModel.Category("category")]
Assert.AreEqual("category", option.Category);
//[System.ComponentModel.Browsable(false)]
Assert.AreEqual(false, option.Visible);
//[System.ComponentModel.DefaultValue(-1)]
Assert.AreEqual(-1, option.Value);

{
    CommandFilterAttribute a = new CommandFilterAttribute();
    Assert.IsFalse(a.Visible);
    a.Visible = true;
    Assert.IsFalse(a.Visible);
}
{
    CommandAttribute a = new CommandAttribute();
    a.DisplayName = "test";
    a.AliasNames = new string[] { "alias" };
    Assert.AreEqual("test,alias", String.Join(",", a.AllNames));
    IDisplayInfo di = a;
    di.Help();//no-op
}
{
    AllArgumentsAttribute a = new AllArgumentsAttribute();
    Assert.AreEqual(typeof(AllArgumentsAttribute), a.GetType());
}
VB.NETCopy Code
Dim ci As New CommandInterpreter(New TestCommands())

Dim [option] As IOption = ci.Options(0)

'[Option("Other")]
Assert.AreEqual("Other", [option].DisplayName)
Assert.AreEqual(GetType(Integer), [option].Type)
'[AliasName("alias")]
'[System.ComponentModel.DisplayName("ingored-due-to-OptionAttribute")]
Assert.AreEqual(2, [option].AllNames.Length)
Assert.IsTrue(New List(Of String)([option].AllNames).Contains("Other"))
Assert.IsTrue(New List(Of String)([option].AllNames).Contains("alias"))
'[System.ComponentModel.Description("description")]
Assert.AreEqual("description", [option].Description)
'[System.ComponentModel.Category("category")]
Assert.AreEqual("category", [option].Category)
'[System.ComponentModel.Browsable(false)]
Assert.AreEqual(False, [option].Visible)
'[System.ComponentModel.DefaultValue(-1)]
Assert.AreEqual(-1, [option].Value)

If True Then
    Dim a As New CommandFilterAttribute()
    Assert.IsFalse(a.Visible)
    a.Visible = True
    Assert.IsFalse(a.Visible)
End If
If True Then
    Dim a As New CommandAttribute()
    a.DisplayName = "test"
    a.AliasNames = New String() {"alias"}
    Assert.AreEqual("test,alias", [String].Join(",", a.AllNames))
    Dim di As IDisplayInfo = a
    di.Help()
    'no-op
End If
If True Then
    Dim a As New AllArgumentsAttribute()
    Assert.AreEqual(GetType(AllArgumentsAttribute), a.[GetType]())
End If

Inheritance Hierarchy

System.Object
   System.Attribute
      CSharpTest.Net.Commands.DisplayInfoAttribute
         CSharpTest.Net.Commands.CommandAttribute

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys