Skip to content

System.Windows.Forms.MenuItem is not working #3

@Inmobilis

Description

@Inmobilis

internal class Command : WeakReference

Should use "System.Windows.Forms.Command" in assembly "System.Windows.Forms".

Simple code:

internal class Command : IDisposable
{
    private static readonly Type CommandType = typeof(Control).Assembly.GetType(typeof(Command).FullName);
    private static readonly Reflection.PropertyInfo CommandIDProperty = CommandType.GetProperty(nameof(ID), typeof(Int32));
    private static readonly Reflection.MethodInfo CommandDisposeMethod = CommandType.GetMethod(nameof(Dispose), Type.EmptyTypes);

    private readonly Object cmd;

    public Command(ICommandExecutor target) => this.cmd = Activator.CreateInstance(CommandType, target);

    public Int32 ID => (Int32)CommandIDProperty.GetValue(this.cmd);

    public void Dispose() => CommandDisposeMethod.Invoke(this.cmd, null);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions