Add Clear to ILProcessor #662

Merged
MichalPetryka merged 1 commit from il-clear into master 2020-05-20 19:45:49 -05:00
MichalPetryka commented 2020-04-22 03:41:18 -05:00 (Migrated from github.com)

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

Clear can be useful when you need to rewrite a method from scratch.
jbevain commented 2020-05-20 19:45:52 -05:00 (Migrated from github.com)

Thanks!

Thanks!
ltrzesniewski commented 2020-05-21 04:05:22 -05:00 (Migrated from github.com)

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.

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](https://github.com/ltrzesniewski/InlineIL.Fody/blob/2b63811da7cf22473a174989f98f225a3083c136/src/InlineIL.Fody/ModuleWeaver.cs#L63-L71): ```C# 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 commented 2020-05-21 12:22:43 -05:00 (Migrated from github.com)

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

@ltrzesniewski yeah I think that's a different subject. At that point you might be better off creating a new method body.
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil!662
No description provided.