Skip to content

Add Clear to ILProcessor - #662

Merged
jbevain merged 1 commit into
jbevain:masterfrom
MichalPetryka:il-clear
May 21, 2020
Merged

jbevain merged 1 commit into
jbevain:masterfrom
MichalPetryka:il-clear

Conversation

@MichalPetryka

Copy link
Copy Markdown
Contributor

Clear can be useful when you need to rewrite a method from scratch.

@jbevain
jbevain merged commit c1a3c19 into jbevain:master May 21, 2020
@jbevain

jbevain commented May 21, 2020

Copy link
Copy Markdown
Owner

Thanks!

@ltrzesniewski

Copy link
Copy Markdown
Contributor

Hmmm.... If you want to rewrite a method from scratch, there's a whole lot of other stuff you need to remove. I'm doing the following in a project of mine:

method.Body.Instructions.Clear();
method.Body.Variables.Clear();
method.Body.ExceptionHandlers.Clear();

method.DebugInformation.SequencePoints.Clear();
method.DebugInformation.Scope = null;
method.DebugInformation.StateMachineKickOffMethod = null;

method.CustomDebugInformations.Clear();

On the other hand, the ILProcessor only deals with the instruction list today, so I suppose making it clear a bunch of other stuff would not be appropriate.

@jbevain

jbevain commented May 21, 2020

Copy link
Copy Markdown
Owner

@ltrzesniewski yeah I think that's a different subject. At that point you might be better off creating a new method body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants