public void Run(AstNode compilationUnit) { foreach (InvocationExpression invocation in compilationUnit.Descendants.OfType <InvocationExpression>()) { MemberReferenceExpression mre = invocation.Target as MemberReferenceExpression; IMethod methodReference = invocation.Annotation <IMethod>(); if (mre != null && mre.Target is TypeReferenceExpression && methodReference != null && invocation.Arguments.Any()) { MethodDef d = methodReference.Resolve(); if (d != null) { var ca = d.Find(systemRuntimeCompilerServicesString, extensionAttributeString); if (ca != null) { var firstArgument = invocation.Arguments.First(); if (firstArgument is NullReferenceExpression) { firstArgument = firstArgument.ReplaceWith(expr => expr.CastTo(AstBuilder.ConvertType(d.Parameters.SkipNonNormal().First().Type, stringBuilder))); } else { var ilRanges = mre.Target.GetAllRecursiveILRanges(); mre.Target = firstArgument.Detach(); if (ilRanges.Count > 0) { mre.Target.AddAnnotation(ilRanges); } } if (invocation.Arguments.Any()) { // HACK: removing type arguments should be done indepently from whether a method is an extension method, // just by testing whether the arguments can be inferred var ilRanges = mre.TypeArguments.GetAllRecursiveILRanges(); mre.TypeArguments.Clear(); if (ilRanges.Count > 0) { mre.AddAnnotation(ilRanges); } } } } } } }