문제

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?

도움이 되었습니까?

해결책

Variables don't have names once compiled. Information like that is stored in the pdb file, not the assembly itself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top