Replies: 1 comment 1 reply
-
Had a go at this again and, after a lot of trial and error, ended up with something that works, though I barely know how. public class ResolveGameVersionLiteral : IAstTransform {
public void Run(AstNode rootNode, TransformContext context) {
foreach (var section in rootNode.Descendants.OfType<InvocationExpression>().Where(e => e.Arguments.Count > 0)) {
var method = (IMethod)section.GetSymbol();
if (method.FullName == "System.IO.BinaryWriter.Write" && (method.Parameters[0]?.Type.IsKnownType(KnownTypeCode.Int32) ?? false)) {
var firstArgument = section.Arguments.First();
if (firstArgument is PrimitiveExpression expression && expression.Value is int value && value == C.GameVersion) {
firstArgument = firstArgument.ReplaceWith(expr => new MemberReferenceExpression(new IdentifierExpression("Misc"), "GAME_VERSION"));
}
}
}
}
} The goal was to replace any calls to Would appreciate any advice on how to improve the logic, such as the checking for the correct method. Also, is there any way to pass the searched value into the transform, or do I have to store it as some class field like this? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Using ICSharpCode.Decompiler, can I somehow (selectively) resolve literal values back to a constant? I probably don't want to do it across the board, but something like selecting specific method arguments, possibly for calls within specific methods.
Similar to the following issue, except not as a default.
#3222
Beta Was this translation helpful? Give feedback.
All reactions