private static ReflectedMemberKind? GetMemberKind(ICSharpInvocationInfo argumentsOwner) { if (argumentsOwner != null && argumentsOwner.Reference != null) { switch (argumentsOwner.Reference.GetName()) { case "GetMethod": return ReflectedMemberKind.Method; case "GetProperty": return ReflectedMemberKind.Property; case "GetField": return ReflectedMemberKind.Field; case "GetEvent": return ReflectedMemberKind.Event; case "GetMember": return ReflectedMemberKind.Any; } } return null; }
private static void CheckInvocationInfo( [NotNull] ICSharpInvocationInfo invocationInfo, [CanBeNull] ITreeNode invocationAnchor, [NotNull] IHighlightingConsumer consumer) { var invocationReference = invocationInfo.Reference; if (invocationReference == null) { return; } var(declaredElement, _, resolveErrorType) = invocationReference.Resolve(); var parametersOwner = declaredElement as IParametersOwner; if (parametersOwner == null) { return; } if (resolveErrorType != ResolveErrorType.OK) { return; } var parameters = parametersOwner.Parameters; if (parameters.Count == 0) { return; } var lastParameter = parameters[parameters.Count - 1]; if (!lastParameter.IsParameterArray) { return; } ICSharpExpression paramsArgument = null; foreach (var argumentInfo in invocationInfo.Arguments) { var parameter = argumentInfo.MatchingParameter; if (parameter == null) { continue; } if (!Equals(parameter.Element, lastParameter)) { continue; } // found explicit array pass if (parameter.Expanded == ArgumentsUtil.ExpandedKind.None) { return; } if (argumentInfo is ICSharpArgument argument) { paramsArgument = argument.Value; } break; } var anchor = invocationAnchor ?? paramsArgument ?? invocationInfo as ICSharpExpression; if (anchor == null) { return; } // todo: wrong! only when no if (paramsArgument == null && IsCachedEmptyArrayAvailable(anchor)) { return; } var expression = anchor as ICSharpExpression; var paramsRange = expression?.GetExpressionRange() ?? anchor.GetDocumentRange(); var description = $"parameters array '{lastParameter.ShortName}' creation"; consumer.AddHighlighting(new ObjectAllocationHighlighting(anchor, description), paramsRange); }