Browse Source

Inline variable declarations/modernize parts of our code base.

pull/1984/head
Siegfried Pammer 5 years ago
parent
commit
8925b4ff7b
  1. 9
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  2. 24
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 3
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs
  4. 9
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs
  5. 3
      ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs
  6. 3
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  7. 3
      ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs
  8. 3
      ICSharpCode.Decompiler/CSharp/Transforms/FixNameCollisions.cs
  9. 3
      ICSharpCode.Decompiler/Documentation/IdStringProvider.cs
  10. 3
      ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs
  11. 7
      ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs
  12. 18
      ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs
  13. 3
      ICSharpCode.Decompiler/IL/BlockBuilder.cs
  14. 6
      ICSharpCode.Decompiler/IL/ControlFlow/DetectPinnedRegions.cs
  15. 3
      ICSharpCode.Decompiler/IL/Transforms/DynamicCallSiteTransform.cs
  16. 4
      ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs
  17. 9
      ILSpy.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs

9
ICSharpCode.Decompiler/CSharp/Annotations.cs

@ -155,8 +155,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// </summary> /// </summary>
public static ILVariable GetILVariable(this IdentifierExpression expr) public static ILVariable GetILVariable(this IdentifierExpression expr)
{ {
var rr = expr.Annotation<ResolveResult>() as ILVariableResolveResult; if (expr.Annotation<ResolveResult>() is ILVariableResolveResult rr)
if (rr != null)
return rr.Variable; return rr.Variable;
else else
return null; return null;
@ -167,8 +166,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// </summary> /// </summary>
public static ILVariable GetILVariable(this VariableInitializer vi) public static ILVariable GetILVariable(this VariableInitializer vi)
{ {
var rr = vi.Annotation<ResolveResult>() as ILVariableResolveResult; if (vi.Annotation<ResolveResult>() is ILVariableResolveResult rr)
if (rr != null)
return rr.Variable; return rr.Variable;
else else
return null; return null;
@ -179,8 +177,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// </summary> /// </summary>
public static ILVariable GetILVariable(this ForeachStatement loop) public static ILVariable GetILVariable(this ForeachStatement loop)
{ {
var rr = loop.Annotation<ResolveResult>() as ILVariableResolveResult; if (loop.Annotation<ResolveResult>() is ILVariableResolveResult rr)
if (rr != null)
return rr.Variable; return rr.Variable;
else else
return null; return null;

24
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -383,14 +383,13 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitLocAllocSpan(LocAllocSpan inst, TranslationContext context) protected internal override TranslatedExpression VisitLocAllocSpan(LocAllocSpan inst, TranslationContext context)
{ {
return TranslateLocAllocSpan(inst, context.TypeHint, out var elementType) return TranslateLocAllocSpan(inst, context.TypeHint, out _)
.WithILInstruction(inst).WithRR(new ResolveResult(inst.Type)); .WithILInstruction(inst).WithRR(new ResolveResult(inst.Type));
} }
StackAllocExpression TranslateLocAllocSpan(LocAllocSpan inst, IType typeHint, out IType elementType) StackAllocExpression TranslateLocAllocSpan(LocAllocSpan inst, IType typeHint, out IType elementType)
{ {
elementType = inst.Type.TypeArguments[0]; elementType = inst.Type.TypeArguments[0];
PointerType pointerType = new PointerType(elementType);
TranslatedExpression countExpression = Translate(inst.Argument) TranslatedExpression countExpression = Translate(inst.Argument)
.ConvertTo(compilation.FindType(KnownTypeCode.Int32), this); .ConvertTo(compilation.FindType(KnownTypeCode.Int32), this);
return new StackAllocExpression { return new StackAllocExpression {
@ -696,8 +695,7 @@ namespace ICSharpCode.Decompiler.CSharp
return ErrorExpression("Nullable comparisons with three-valued-logic not supported in C#"); return ErrorExpression("Nullable comparisons with three-valued-logic not supported in C#");
} }
if (inst.Kind.IsEqualityOrInequality()) { if (inst.Kind.IsEqualityOrInequality()) {
bool negateOutput; var result = TranslateCeq(inst, out bool negateOutput);
var result = TranslateCeq(inst, out negateOutput);
if (negateOutput) if (negateOutput)
return LogicNot(result).WithILInstruction(inst); return LogicNot(result).WithILInstruction(inst);
else else
@ -2573,31 +2571,29 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
var stloc = block.Instructions.FirstOrDefault() as StLoc; var stloc = block.Instructions.FirstOrDefault() as StLoc;
var final = block.FinalInstruction as LdLoc; var final = block.FinalInstruction as LdLoc;
IType type; if (stloc == null || final == null || !stloc.Value.MatchNewArr(out IType type))
if (stloc == null || final == null || !stloc.Value.MatchNewArr(out type) || stloc.Variable != final.Variable || stloc.Variable.Kind != VariableKind.InitializerTarget) throw new ArgumentException("given Block is invalid!");
if (stloc.Variable != final.Variable || stloc.Variable.Kind != VariableKind.InitializerTarget)
throw new ArgumentException("given Block is invalid!"); throw new ArgumentException("given Block is invalid!");
var newArr = (NewArr)stloc.Value; var newArr = (NewArr)stloc.Value;
var translatedDimensions = newArr.Indices.Select(i => Translate(i)).ToArray(); var translatedDimensions = newArr.Indices.SelectArray(i => Translate(i));
if (!translatedDimensions.All(dim => dim.ResolveResult.IsCompileTimeConstant)) if (!translatedDimensions.All(dim => dim.ResolveResult.IsCompileTimeConstant))
throw new ArgumentException("given Block is invalid!"); throw new ArgumentException("given Block is invalid!");
int dimensions = newArr.Indices.Count; int dimensions = newArr.Indices.Count;
int[] dimensionSizes = translatedDimensions.Select(dim => (int)dim.ResolveResult.ConstantValue).ToArray(); int[] dimensionSizes = translatedDimensions.SelectArray(dim => (int)dim.ResolveResult.ConstantValue);
var container = new Stack<ArrayInitializer>(); var container = new Stack<ArrayInitializer>();
var root = new ArrayInitializer(new ArrayInitializerExpression()); var root = new ArrayInitializer(new ArrayInitializerExpression());
container.Push(root); container.Push(root);
var elementResolveResults = new List<ResolveResult>(); var elementResolveResults = new List<ResolveResult>();
for (int i = 1; i < block.Instructions.Count; i++) { for (int i = 1; i < block.Instructions.Count; i++) {
ILInstruction target, value, array; if (!block.Instructions[i].MatchStObj(out ILInstruction target, out ILInstruction value, out IType t) || !type.Equals(t))
IType t;
ILVariable v;
if (!block.Instructions[i].MatchStObj(out target, out value, out t) || !type.Equals(t))
throw new ArgumentException("given Block is invalid!"); throw new ArgumentException("given Block is invalid!");
if (!target.MatchLdElema(out t, out array) || !type.Equals(t)) if (!target.MatchLdElema(out t, out ILInstruction array) || !type.Equals(t))
throw new ArgumentException("given Block is invalid!"); throw new ArgumentException("given Block is invalid!");
if (!array.MatchLdLoc(out v) || v != final.Variable) if (!array.MatchLdLoc(out ILVariable v) || v != final.Variable)
throw new ArgumentException("given Block is invalid!"); throw new ArgumentException("given Block is invalid!");
while (container.Count < dimensions) { while (container.Count < dimensions) {
var aie = new ArrayInitializerExpression(); var aie = new ArrayInitializerExpression();

3
ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs

@ -163,8 +163,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
throw new ArgumentNullException(nameof(toType)); throw new ArgumentNullException(nameof(toType));
TypePair pair = new TypePair(fromType, toType); TypePair pair = new TypePair(fromType, toType);
Conversion c; if (implicitConversionCache.TryGetValue(pair, out Conversion c))
if (implicitConversionCache.TryGetValue(pair, out c))
return c; return c;
c = ImplicitConversion(fromType, toType, allowUserDefined: true, allowTuple: true); c = ImplicitConversion(fromType, toType, allowUserDefined: true, allowTuple: true);

9
ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs

@ -1740,8 +1740,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
void CheckForEnumerableInterface(ResolveResult expression, out IType collectionType, out IType enumeratorType, out IType elementType, out ResolveResult getEnumeratorInvocation) void CheckForEnumerableInterface(ResolveResult expression, out IType collectionType, out IType enumeratorType, out IType elementType, out ResolveResult getEnumeratorInvocation)
{ {
bool? isGeneric; elementType = expression.Type.GetElementTypeFromIEnumerable(compilation, false, out bool? isGeneric);
elementType = expression.Type.GetElementTypeFromIEnumerable(compilation, false, out isGeneric);
if (isGeneric == true) { if (isGeneric == true) {
ITypeDefinition enumerableOfT = compilation.FindType(KnownTypeCode.IEnumerableOfT).GetDefinition(); ITypeDefinition enumerableOfT = compilation.FindType(KnownTypeCode.IEnumerableOfT).GetDefinition();
if (enumerableOfT != null) if (enumerableOfT != null)
@ -1886,8 +1885,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
TypeInference ti = new TypeInference(compilation, conversions); TypeInference ti = new TypeInference(compilation, conversions);
ResolveResult[] arguments = { new ResolveResult(targetType) }; ResolveResult[] arguments = { new ResolveResult(targetType) };
IType[] parameterTypes = { method.Parameters[0].Type }; IType[] parameterTypes = { method.Parameters[0].Type };
bool success; var inferredTypes = ti.InferTypeArguments(method.TypeParameters, arguments, parameterTypes, out _);
var inferredTypes = ti.InferTypeArguments(method.TypeParameters, arguments, parameterTypes, out success);
var substitution = new TypeParameterSubstitution(null, inferredTypes); var substitution = new TypeParameterSubstitution(null, inferredTypes);
// Validate that the types that could be inferred (aren't unknown) satisfy the constraints: // Validate that the types that could be inferred (aren't unknown) satisfy the constraints:
bool hasInferredTypes = false; bool hasInferredTypes = false;
@ -2563,8 +2561,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
throw new ArgumentException("sizeArguments.Length must not be 0"); throw new ArgumentException("sizeArguments.Length must not be 0");
if (elementType == null) { if (elementType == null) {
TypeInference typeInference = new TypeInference(compilation, conversions); TypeInference typeInference = new TypeInference(compilation, conversions);
bool success; elementType = typeInference.GetBestCommonType(initializerElements, out _);
elementType = typeInference.GetBestCommonType(initializerElements, out success);
} }
IType arrayType = new ArrayType(compilation, elementType, dimensions); IType arrayType = new ArrayType(compilation, elementType, dimensions);

3
ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs

@ -199,8 +199,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
foreach (var methodGroup in GetExtensionMethods()) { foreach (var methodGroup in GetExtensionMethods()) {
var outputGroup = new List<IMethod>(); var outputGroup = new List<IMethod>();
foreach (var method in methodGroup) { foreach (var method in methodGroup) {
IType[] inferredTypes; if (CSharpResolver.IsEligibleExtensionMethod(this.TargetType, method, true, out IType[] inferredTypes)) {
if (CSharpResolver.IsEligibleExtensionMethod(this.TargetType, method, true, out inferredTypes)) {
if (substituteInferredTypes && inferredTypes != null) { if (substituteInferredTypes && inferredTypes != null) {
outputGroup.Add(method.Specialize(new TypeParameterSubstitution(null, inferredTypes))); outputGroup.Add(method.Specialize(new TypeParameterSubstitution(null, inferredTypes)));
} else { } else {

3
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -1047,8 +1047,7 @@ namespace ICSharpCode.Decompiler.CSharp
blockStatement.Add(Convert(block.FinalInstruction)); blockStatement.Add(Convert(block.FinalInstruction));
} }
} }
string label; if (endContainerLabels.TryGetValue(container, out string label)) {
if (endContainerLabels.TryGetValue(container, out label)) {
if (isLoop && !(blockStatement.LastOrDefault() is ContinueStatement)) { if (isLoop && !(blockStatement.LastOrDefault() is ContinueStatement)) {
blockStatement.Add(new ContinueStatement()); blockStatement.Add(new ContinueStatement());
} }

3
ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs

@ -282,8 +282,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
} }
} }
} }
VariableToDeclare v; if (variableDict.TryGetValue(variable, out VariableToDeclare v)) {
if (variableDict.TryGetValue(variable, out v)) {
v.InsertionPoint = FindCommonParent(v.InsertionPoint, newPoint); v.InsertionPoint = FindCommonParent(v.InsertionPoint, newPoint);
} else { } else {
v = new VariableToDeclare(variable, variable.HasInitialValue, v = new VariableToDeclare(variable, variable.HasInitialValue,

3
ICSharpCode.Decompiler/CSharp/Transforms/FixNameCollisions.cs

@ -61,8 +61,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
foreach (var node in rootNode.DescendantsAndSelf) { foreach (var node in rootNode.DescendantsAndSelf) {
if (node is IdentifierExpression || node is MemberReferenceExpression) { if (node is IdentifierExpression || node is MemberReferenceExpression) {
ISymbol symbol = node.GetSymbol(); ISymbol symbol = node.GetSymbol();
string newName; if (symbol != null && renamedSymbols.TryGetValue(symbol, out string newName)) {
if (symbol != null && renamedSymbols.TryGetValue(symbol, out newName)) {
node.GetChildByRole(Roles.Identifier).Name = newName; node.GetChildByRole(Roles.Identifier).Name = newName;
} }
} }

3
ICSharpCode.Decompiler/Documentation/IdStringProvider.cs

@ -296,8 +296,7 @@ namespace ICSharpCode.Decompiler.Documentation
} else { } else {
// not a type parameter reference: read the actual type name // not a type parameter reference: read the actual type name
List<ITypeReference> typeArguments = new List<ITypeReference>(); List<ITypeReference> typeArguments = new List<ITypeReference>();
int typeParameterCount; string typeNameWithoutSuffix = ReadTypeName(typeName, ref pos, true, out int typeParameterCount, typeArguments);
string typeNameWithoutSuffix = ReadTypeName(typeName, ref pos, true, out typeParameterCount, typeArguments);
result = new GetPotentiallyNestedClassTypeReference(typeNameWithoutSuffix, typeParameterCount); result = new GetPotentiallyNestedClassTypeReference(typeNameWithoutSuffix, typeParameterCount);
while (pos < typeName.Length && typeName[pos] == '.') { while (pos < typeName.Length && typeName[pos] == '.') {
pos++; pos++;

3
ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs

@ -51,8 +51,7 @@ namespace ICSharpCode.Decompiler.Documentation
if (module == null) if (module == null)
throw new ArgumentNullException(nameof(module)); throw new ArgumentNullException(nameof(module));
lock (cache) { lock (cache) {
XmlDocumentationProvider xmlDoc; if (!cache.TryGetValue(module, out XmlDocumentationProvider xmlDoc)) {
if (!cache.TryGetValue(module, out xmlDoc)) {
string xmlDocFile = LookupLocalizedXmlDoc(module.FileName); string xmlDocFile = LookupLocalizedXmlDoc(module.FileName);
if (xmlDocFile == null) { if (xmlDocFile == null) {
xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FileName), module.GetRuntime()); xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FileName), module.GetRuntime());

7
ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs

@ -266,10 +266,8 @@ namespace ICSharpCode.Decompiler.Documentation
int b = fs.ReadByte(); int b = fs.ReadByte();
if (b < 0) if (b < 0)
throw new EndOfStreamException(); throw new EndOfStreamException();
int bytesUsed, charsUsed;
bool completed;
input[0] = (byte)b; input[0] = (byte)b;
decoder.Convert(input, 0, 1, output, 0, 1, false, out bytesUsed, out charsUsed, out completed); decoder.Convert(input, 0, 1, output, 0, 1, false, out int bytesUsed, out int charsUsed, out _);
Debug.Assert(bytesUsed == 1); Debug.Assert(bytesUsed == 1);
if (charsUsed == 1) { if (charsUsed == 1) {
if ((prevChar != '\r' && output[0] == '\n') || output[0] == '\r') if ((prevChar != '\r' && output[0] == '\n') || output[0] == '\r')
@ -357,8 +355,7 @@ namespace ICSharpCode.Decompiler.Documentation
XmlDocumentationCache cache = this.cache; XmlDocumentationCache cache = this.cache;
lock (cache) { lock (cache) {
string val; if (!cache.TryGet(key, out string val)) {
if (!cache.TryGet(key, out val)) {
try { try {
// go through all items that have the correct hash // go through all items that have the correct hash
while (++m < index.Length && index[m].HashCode == hashcode) { while (++m < index.Length && index[m].HashCode == hashcode) {

18
ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs

@ -235,9 +235,8 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
{ {
#if DEBUG #if DEBUG
Debug.Assert(initialized, "Initialize() was not called"); Debug.Assert(initialized, "Initialize() was not called");
State previousState; if (debugDict.TryGetValue(inst, out State previousState)) {
if (debugDict.TryGetValue(inst, out previousState)) {
Debug.Assert(previousState.LessThanOrEqual(state)); Debug.Assert(previousState.LessThanOrEqual(state));
previousState.JoinWith(state); previousState.JoinWith(state);
} else { } else {
@ -246,7 +245,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
debugDict.Add(inst, state.Clone()); debugDict.Add(inst, state.Clone());
} }
} }
// currentStateOnException should be all states within the try block joined together // currentStateOnException should be all states within the try block joined together
// -> state should already have been joined into currentStateOnException. // -> state should already have been joined into currentStateOnException.
Debug.Assert(state.LessThanOrEqual(currentStateOnException)); Debug.Assert(state.LessThanOrEqual(currentStateOnException));
@ -344,8 +343,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
/// </remarks> /// </remarks>
State GetBlockInputState(Block block) State GetBlockInputState(Block block)
{ {
State s; if (stateOnBranch.TryGetValue(block, out State s)) {
if (stateOnBranch.TryGetValue(block, out s)) {
return s; return s;
} else { } else {
s = bottomState.Clone(); s = bottomState.Clone();
@ -388,8 +386,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
state.ReplaceWith(stateOnBranch[block]); state.ReplaceWith(stateOnBranch[block]);
block.AcceptVisitor(this); block.AcceptVisitor(this);
} }
State stateOnExit; if (stateOnLeave.TryGetValue(container, out State stateOnExit)) {
if (stateOnLeave.TryGetValue(container, out stateOnExit)) {
state.ReplaceWith(stateOnExit); state.ReplaceWith(stateOnExit);
} else { } else {
MarkUnreachable(); MarkUnreachable();
@ -476,14 +473,13 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
protected State HandleTryBlock(TryInstruction inst) protected State HandleTryBlock(TryInstruction inst)
{ {
State oldStateOnException = currentStateOnException; State oldStateOnException = currentStateOnException;
State newStateOnException; if (stateOnException.TryGetValue(inst, out State newStateOnException)) {
if (stateOnException.TryGetValue(inst, out newStateOnException)) {
newStateOnException.JoinWith(state); newStateOnException.JoinWith(state);
} else { } else {
newStateOnException = state.Clone(); newStateOnException = state.Clone();
stateOnException.Add(inst, newStateOnException); stateOnException.Add(inst, newStateOnException);
} }
currentStateOnException = newStateOnException; currentStateOnException = newStateOnException;
inst.TryBlock.AcceptVisitor(this); inst.TryBlock.AcceptVisitor(this);
// swap back to the old object instance // swap back to the old object instance

3
ICSharpCode.Decompiler/IL/BlockBuilder.cs

@ -142,8 +142,7 @@ namespace ICSharpCode.Decompiler.IL
} }
} }
// Enter a handler if necessary // Enter a handler if necessary
BlockContainer handlerContainer; if (handlerContainers.TryGetValue(start, out BlockContainer handlerContainer)) {
if (handlerContainers.TryGetValue(start, out handlerContainer)) {
containerStack.Push(currentContainer); containerStack.Push(currentContainer);
currentContainer = handlerContainer; currentContainer = handlerContainer;
currentBlock = handlerContainer.EntryPoint; currentBlock = handlerContainer.EntryPoint;

6
ICSharpCode.Decompiler/IL/ControlFlow/DetectPinnedRegions.cs

@ -94,8 +94,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
var block = container.Blocks[i]; var block = container.Blocks[i];
for (int j = 0; j < block.Instructions.Count - 1; j++) { for (int j = 0; j < block.Instructions.Count - 1; j++) {
var inst = block.Instructions[j]; var inst = block.Instructions[j];
ILVariable v; if (inst.MatchStLoc(out ILVariable v) && v.Kind == VariableKind.PinnedLocal) {
if (inst.MatchStLoc(out v) && v.Kind == VariableKind.PinnedLocal) {
if (block.Instructions[j + 1].OpCode != OpCode.Branch) { if (block.Instructions[j + 1].OpCode != OpCode.Branch) {
// split block after j: // split block after j:
context.Step("Split block after pinned local write", inst); context.Step("Split block after pinned local write", inst);
@ -357,10 +356,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
// stloc P(ldelema(ldloc V, ldc.i4 0, ...)) // stloc P(ldelema(ldloc V, ldc.i4 0, ...))
// br B_target // br B_target
// } // }
ILInstruction value;
if (block.Instructions.Count != 2) if (block.Instructions.Count != 2)
return false; return false;
if (!block.Instructions[0].MatchStLoc(out var p2, out value)) if (!block.Instructions[0].MatchStLoc(out var p2, out ILInstruction value))
return false; return false;
if (p != p2) { if (p != p2) {
// If the pointer is unused, the variable P might have been split. // If the pointer is unused, the variable P might have been split.

3
ICSharpCode.Decompiler/IL/Transforms/DynamicCallSiteTransform.cs

@ -522,8 +522,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
if (!createCall.Arguments[0].MatchLdcI4(out var argumentInfoFlags)) if (!createCall.Arguments[0].MatchLdcI4(out var argumentInfoFlags))
return false; return false;
string argumentName = null; if (!createCall.Arguments[1].MatchLdStr(out string argumentName))
if (!createCall.Arguments[1].MatchLdStr(out argumentName))
if (!createCall.Arguments[1].MatchLdNull()) if (!createCall.Arguments[1].MatchLdNull())
return false; return false;
callSiteInfo.ArgumentInfos[i] = new CSharpArgumentInfo { Flags = (CSharpArgumentInfoFlags)argumentInfoFlags, Name = argumentName, CompileTimeType = compileTimeTypes[i + 1] }; callSiteInfo.ArgumentInfos[i] = new CSharpArgumentInfo { Flags = (CSharpArgumentInfoFlags)argumentInfoFlags, Name = argumentName, CompileTimeType = compileTimeTypes[i + 1] };

4
ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs

@ -21,8 +21,8 @@ namespace ILSpy.BamlDecompiler
public ILSpyTreeNode CreateNode(string key, object data) public ILSpyTreeNode CreateNode(string key, object data)
{ {
if (key.EndsWith(".baml", StringComparison.OrdinalIgnoreCase) && data is Stream) if (key.EndsWith(".baml", StringComparison.OrdinalIgnoreCase) && data is Stream stream)
return new BamlResourceEntryNode(key, (Stream)data); return new BamlResourceEntryNode(key, stream);
else else
return null; return null;
} }

9
ILSpy.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs

@ -114,8 +114,7 @@ namespace ILSpy.BamlDecompiler.Rewrite
var comp = ifInst.Condition as Comp; var comp = ifInst.Condition as Comp;
if (comp.Kind != ComparisonKind.Inequality && comp.Kind != ComparisonKind.Equality) if (comp.Kind != ComparisonKind.Inequality && comp.Kind != ComparisonKind.Equality)
continue; continue;
int id; if (!comp.Right.MatchLdcI4(out int id))
if (!comp.Right.MatchLdcI4(out id))
continue; continue;
var events = FindEvents(comp.Kind == ComparisonKind.Inequality ? ifInst.FalseInst : ifInst.TrueInst); var events = FindEvents(comp.Kind == ComparisonKind.Inequality ? ifInst.FalseInst : ifInst.TrueInst);
result.Add((new LongSet(id), events)); result.Add((new LongSet(id), events));
@ -150,8 +149,7 @@ namespace ILSpy.BamlDecompiler.Rewrite
if (call == null || call.OpCode == OpCode.NewObj) if (call == null || call.OpCode == OpCode.NewObj)
return; return;
string eventName, handlerName; if (IsAddEvent(call, out string eventName, out string handlerName) || IsAddAttachedEvent(call, out eventName, out handlerName))
if (IsAddEvent(call, out eventName, out handlerName) || IsAddAttachedEvent(call, out eventName, out handlerName))
events.Add(new EventRegistration { EventName = eventName, MethodName = handlerName }); events.Add(new EventRegistration { EventName = eventName, MethodName = handlerName });
} }
@ -164,8 +162,7 @@ namespace ILSpy.BamlDecompiler.Rewrite
var addMethod = call.Method; var addMethod = call.Method;
if (addMethod.Name != "AddHandler" || addMethod.Parameters.Count != 2) if (addMethod.Name != "AddHandler" || addMethod.Parameters.Count != 2)
return false; return false;
IField field; if (!call.Arguments[1].MatchLdsFld(out IField field))
if (!call.Arguments[1].MatchLdsFld(out field))
return false; return false;
eventName = field.DeclaringType.Name + "." + field.Name; eventName = field.DeclaringType.Name + "." + field.Name;
if (eventName.EndsWith("Event", StringComparison.Ordinal) && eventName.Length > "Event".Length) if (eventName.EndsWith("Event", StringComparison.Ordinal) && eventName.Length > "Event".Length)

Loading…
Cancel
Save