Mono.Cecil TypeReference modifies TypeDefinition
i have this code:
the problem is the second line in the if statement body, it seems like it also modifies the class the member belongs to, and not only the reference to it, any idea why?
5 Replies
before the modification: > Assembly.MainModule.Types:
{Mono.Cecil.TypeDefinition[5]}
[0]: {<Module>}
[1]: {Microsoft.CodeAnalysis.EmbeddedAttribute}
[2]: {System.Runtime.CompilerServices.RefSafetyRulesAttribute}
[3]: {Hello.Creator}
[4]: {Hello.Program}
after:
{Mono.Cecil.TypeDefinition[5]}
[0]: {<Module>}
[1]: {Microsoft.CodeAnalysis.EmbeddedAttribute}
[2]: {System.Runtime.CompilerServices.RefSafetyRulesAttribute}
[3]: {Hello.NamedCreator}
[4]: {Hello.Program}
you see the NamedCreator
That makes sense to me --
Member.DeclaringType
is the type which contains the member, and then you're changing its Name
property
What are you trying to do?But it returns TypeReference and not TypeDefinition, so i would expect to change only this reference to the class(the code it modifies is:
Creator.DoSmth()
)
I thought it would only swap the Creator for NamedCreator and not rename the class itselfI don't know Mono.Cecil particularly well, but I would assume that you'd want to reassign
member.DeclaringType
, not member.DeclaringType.Name
awesome, it seems it was fixed, thanks