private static void CheckInvocation( [NotNull] IInvocationExpression invocationExpression, [NotNull] IHighlightingConsumer consumer) { var expressionReference = invocationExpression.InvocationExpressionReference; if (expressionReference == null) { return; } var method = expressionReference.Resolve().DeclaredElement as IMethod; if (method == null || method.IsExtensionMethod) { return; } var referenceExpression = invocationExpression.InvokedExpression as IReferenceExpression; if (referenceExpression == null) { return; } bool isValueType, typeParameterType = false; var qualifierExpression = referenceExpression.QualifierExpression; if (qualifierExpression == null || qualifierExpression is IBaseExpression) { var declaration = invocationExpression.GetContainingTypeDeclaration(); isValueType = (declaration != null && declaration.DeclaredElement is IStruct); } else { var type = qualifierExpression.Type(); typeParameterType = type.IsTypeParameterType(); isValueType = type.IsValueType(); } if (isValueType && method.GetContainingType() is IClass && !method.IsStatic) { // do not produce possible false positive when type is type parameter type if (!typeParameterType || string.Equals( method.ShortName, "GetType", StringComparison.Ordinal)) { consumer.AddHighlighting( new BoxingAllocationHighlighting(invocationExpression, "inherited System.Object virtual method call on value type instance"), referenceExpression.NameIdentifier.GetDocumentRange()); } } }