Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
Can some one fix this problem? plz!
---
I have a class that descripted as the followings:

C#
/// <summary>
/// A class that contains all CommandMethod
/// </summary>
public class Commands
{
    // This class have NO constructor

    [CommandMethod("CommandName", "commandGroup", CommandFlags.Modal | CommandFlags.UsePickSet)]
    public method method1()
    {
    // code for method1
    }

    public method method2(){}

    ...
}



In method1, I need some information that retrieved from an instance of other class. So I have defined a base class like this one:

C#
/// <summary>
/// The base class for all CommandMethod will be created
/// </summary>
public class CommandBased
{
    public CommandBased()
    { }
    
    /// <summary>
    /// Shortcut for command
    /// </summary>
    private string commandShortcut;
    /// <summary>
    /// Group of command
    /// </summary>
    private string commandTags;
    /// <summary>
    /// Description for command
    /// </summary>
    private string commandDesctiption;
    
    public string CommandShortcut
    {
        get { return commandShortcut; }
        set { commandShortcut = value; }
    }
    
    public string CommandTags
    {
        get { return commandTags; }
        set { commandTags = value; }
        }
    
    public string CommandDesctiption
    {
        get { return commandDesctiption; }
        set { commandDesctiption = value; }
    }
    
    ‪#‎region‬ public methods
    /// <summary>
    /// Return command info, it will be used as an attribute in CommandMethod
    /// </summary>
    /// <returns>command info as string</returns>
    public string GenerateCommandInfo()
    {
        return CommandShortcut + "," + CommandTags + "," + CommandDesctiption;
    }
    ‪#‎endregion‬
}


Back to class Commands above, I want to create an instance of CommandBased, set some value for it, eg:
C#
CommandBased thisCommand = new CommandBased
{
    CommandShortcut = "XXX",
    CommandTags = "this is tags",
    CommandDesctiption = "this is a description"
};

then I want to use it's public method (GenerateCommandInfo method) in CommandMethod:
C#
[CommandMethod(thisCommand.GenerateCommandInfo, "commandGroup", CommandFlags.Modal | CommandFlags.UsePickSet)]
public method method1()
{
    // code for method1
}


THE QUESTION: HOW CAN I USE: The question: How can i use:[CommandMethod(thisCommand.GenerateCommandInfo,.......

Thanks!
Posted
Updated 9-Sep-14 3:42am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900