Reputation: 373
I want to rename variables that defined in a method.
suppose my Method is:
public void PrintWelcome() {
StringBuilder myMessageBuilder = new StringBuilder();
int linesCount = 10;
for (int i = 0; i < linesCount; i++) {
myMessageBuilder.Append(Console.ReadLine());
myMessageBuilder.Append(Environment.NewLine);
}
Console.Write(myMessageBuilder.ToString());
}
Then in another project with Mono.Cecil v 0.9.5 i open my Assembly and then
i want to rename myMessageBuilder
and linesCount
by these codes:
foreach (MethodDefinition methodDef in typeDef.Methods) {
if (methodDef.HasBody) {
foreach (var variableDef in methodDef.Body.Variables) {
variableDef.Name = GetRandomName();
}
}
but my variables name didn't change and when i printed variableDef.Name
it printed " "
.
Can anybody help me for renaming my method variables?
Upvotes: 0
Views: 1004
Reputation: 85
Variables don't have names once compiled. Information like that is stored in the pdb file, not the assembly itself.
Upvotes: 1