开发者

Decompile Class that have resource file

I've been decompiled an aplication exe to learn about how they handle command. But I do not know exactly what type of the following file.because the file is inherit from superclass that inherit from system.windows.forms.component but also this file have resource (ExploreCommand.Resx) file in reflector.

[DesignerCategory("Accurate Command Binders"), ToolboxItem(true), DesignTimeVisible(true)] 
internal class ExplorerCommands : CommandBinder 
{ 
    // Fields 
    private static readonly ResourceManager resources = new ResourceManager(typeof(ExplorerCommands)); 

    // Methods 
    protected ExplorerCommands() 
    { 
    } 开发者_StackOverflow社区

    public ExplorerCommands(Control control) : base(control) 
    { 
    } 

    // Properties 
    [Browsable(false)] 
    public Command AboutAccurate    { 
        get 
        { 
            return base.GetCommandForCaller("AboutAccurate ", "CitraKarya.Bisnis.Akunting.UI.Explorer.AboutAccurate ", ""); 
        } 
    }

On every form that using this class, they declarated like this :

this.reportCommands = new CitraKarya.Akunitng.UI.ReportCommands(this);

but I dont know how command class created. They have have syntax diferent with resource class. Can anybody help me? What does it mean? And how implemented this case?

Ough..and this the base class for exploreCommand :

CODE:

[DesignerCategory(""), DesignTimeVisible(false), Designer(typeof(CommandBinderDesigner), typeof(IDesigner)), ProvideProperty("Command", typeof(object)), TypeConverter(typeof(CommandBinderTypeConverter)), ToolboxItem(false)] 
public abstract class CommandBinder : Component 
{ 
              // Methods 
    protected CommandBinder() 
    { 
        this.commands = new Dictionary<object, Command>(); 
        this.InitializeComponent(); 
    } 

    protected CommandBinder(Control parentControl) 
    { 
        this.commands = new Dictionary<object, Command>(); 
        this.parentControl = parentControl; 
        IComponent component = parentControl; 
        if ((component.Site != null) && (component.Site.Container != null)) 
        { 
            component.Site.Container.Add(this); 
        } 
        this.InitializeComponent(); 
    } 

 protected Command GetCommandForCaller(string propertyName, string id, string category) 
    { 
        CommandManager commandManager = CommandManager; 
        Command command = null; 
        if (commandManager != null) 
        { 
            command = commandManager.Commands[id]; 
        } 
        if (command == null) 
        { 
            command = CreateCommand(propertyName, id, category); 
            if (commandManager != null) 
            { 
                commandManager.Commands.Add(command); 
                return command; 
            } 
            CommandsToBeAdded.Add(command); 
        } 
        return command; 
    }


}


Example of resources are strings(text), images, icons etc that one will use in the application. Instead of distributing them as different files, one can embed them into the assembly (exe/dll) and refer from there. In .NET, resource manager is a helper class to refer to these resources. Again many times, resources are associated with particular type (such as form) and known as local resources. In .NET, local resources are categorized by the type they are associated with - essentially, the resource name would have the associated type name prefix. The resource manager would taken type as an argument and then you can refer to related resources by a simple name/key (that is unique within type name). In your case, you can use reflector to see all resources associated with ExplorerCommands type - they will be categorized under particular resx (or will have name such as <Name space>.ExplorerCommands.<resource name>)

As such, resources have typically nothing to do with code logic - they just indicate some constant text or image that app needs to use.

I dont know how command class created.

From code, it appears that classes derived from CommandBinder exposes property for commands - for example, ExplorerCommands has AboutAccurate property. The property getter is in turn calling CommandBinder.GetCommandForCaller that appears to be factory method for Commands. It is looking up in the manager for pre-existing commad and if not it is invoking CreateCommand method to create the command. I believe that resources would not have any relation as far command creation goes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜