Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No events? (WinForms InitializeComponents) #1180

Closed
chrisstophersaur opened this Issue Jun 16, 2018 · 9 comments

Comments

Projects
None yet
5 participants
@chrisstophersaur
Copy link

chrisstophersaur commented Jun 16, 2018

Every time I decompile a program and load it up in visual studios 2017 all the events are empty, for example if their is a button1 and you click it it will make a button1_click_1 instead of using the code button1_click. This happens for every single item. Someone please help me.

@siegfriedpammer

This comment has been minimized.

Copy link
Member

siegfriedpammer commented Jun 16, 2018

I just tested this. Seems that the Visual Studio Windows Forms designer does not like the code the decompiler generates. I will have to investigate further, but I think it will be difficult to fix this. We would have to add special cases for the InitializeComponent method of Windows Forms.

@chrisstophersaur

This comment has been minimized.

Copy link
Author

chrisstophersaur commented Jun 16, 2018

Alrighty, thanks for the quick reply and hopefully you guys can figure it out.

@siegfriedpammer

This comment has been minimized.

Copy link
Member

siegfriedpammer commented Jun 16, 2018

The problem is that the Forms Designer expects events to use explicit method group conversions. That is, it expects button1.Click += new EventHandler(button1_Click); instead of button1.Click += button1_Click;. This can be fixed by setting DecompilerSettings.UseImplicitMethodGroupConversion to false. The default value is true. Unfortunately, this setting cannot be modified from within ILSpy. (If you use the latest build from the build server, it can be turned off, if you switch to C# 1.0, but that is not a very good fix for this problem.)

@kant2002

This comment has been minimized.

Copy link

kant2002 commented Jun 16, 2018

The usual problem with decompilation of Windows Forms is that it produce approximate following problems:

  • BeginInit/EndInit should be written with explicit conversion which does not make sense for the ILSpy. And for me as well, since most controls have BeginInit/EndInit methods
  • Enumeration serialization inside InitializeComponent should always use fully qualified name
  • If Resources used, that provide additional burden for decompilation.
  • Event subscription mentioned earlier.

All these rules should be strictly followed, otherwise Windows Forms designer would not recognize most of the modifications. If @siegfriedpammer think such decompilation is worth to have in the ILSpy I could take a look at this.

@christophwille

This comment has been minimized.

Copy link
Member

christophwille commented Jun 17, 2018

Given that Windows Forms will get another lease of life (netcore3) it might be a good idea to consider this.

@siegfriedpammer

This comment has been minimized.

Copy link
Member

siegfriedpammer commented Jun 17, 2018

I think the best way to implement this is to extend ICSharpCode.Decompiler.IL.Transforms.ILTransformContext and ICSharpCode.Decompiler.CSharp.Transforms.TransformContext with flags like IsWinForms that can be set if the InitializeComponent method of a Form or Control is being decompiled (in CSharpDecompiler.DecompileBody`). We then can use these flags to exclude some transformations and add others.

siegfriedpammer added a commit that referenced this issue Jun 19, 2018

#1180: Add IsWindowsFormsInitializeComponentMethod and disable some t…
…ransforms when processing a Windows Forms InitializeComponent method.

@dgrunwald dgrunwald changed the title No events? No events? (WinForms InitializeComponents) Jul 29, 2018

@AraHaan

This comment has been minimized.

Copy link

AraHaan commented Aug 7, 2018

Also you plan to have it where the form designer code would output in it's own <form name>.Designer.cs/vb?

@siegfriedpammer

This comment has been minimized.

Copy link
Member

siegfriedpammer commented Mar 8, 2019

Currently we have no plans to include support for generating partial classes and moving the InitializeComponent method + control member declarations to a separate file.

@AraHaan

This comment has been minimized.

Copy link

AraHaan commented Mar 13, 2019

I see, My idea was to check if the class inherits from System.Windows.Form.Form (or System.Windows.Forms.UserControl for controls) and then set that IsWinForms to true; on top of that method if you see the entire code body by clicking on the class itself and not the specific method / member in the form / control.

Also, on windows forms controls with resources, the resource manager there must be named resources as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.