Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ protected override void InitializeWorker(CompilationStartAnalysisContext context

#region "IFormatProviderAlternateStringRule Only"
if (stringFormatMemberWithIFormatProviderStringAndParamsObjectParameter != null &&
!oaContext.Options.IsConfiguredToSkipAnalysis(IFormatProviderAlternateStringRule, targetMethod, oaContext.ContainingSymbol, oaContext.Compilation) &&
(targetMethod.Equals(stringFormatMemberWithStringAndObjectParameter) ||
targetMethod.Equals(stringFormatMemberWithStringObjectAndObjectParameter) ||
targetMethod.Equals(stringFormatMemberWithStringObjectObjectAndObjectParameter) ||
targetMethod.Equals(stringFormatMemberWithStringAndParamsObjectParameter)))
targetMethod.Equals(stringFormatMemberWithStringAndParamsObjectParameter)) &&
!oaContext.Options.IsConfiguredToSkipAnalysis(IFormatProviderAlternateStringRule, targetMethod, oaContext.ContainingSymbol, oaContext.Compilation))
Comment on lines 189 to +193
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbol equality should be faster than IsConfiguredToSkipAnalysis

{
// Sample message for IFormatProviderAlternateStringRule: Because the behavior of string.Format(string, object) could vary based on the current user's locale settings,
// replace this call in IFormatProviderStringTest.M() with a call to string.Format(IFormatProvider, string, params object[]).
Expand Down Expand Up @@ -266,19 +266,16 @@ protected override void InitializeWorker(CompilationStartAnalysisContext context

if (!oaContext.Options.IsConfiguredToSkipAnalysis(uiCultureRule, targetMethod, oaContext.ContainingSymbol, oaContext.Compilation))
{
IEnumerable<int> IformatProviderParameterIndices = GetIndexesOfParameterType(targetMethod, iformatProviderType);
foreach (var index in IformatProviderParameterIndices)
foreach (var argument in invocationExpression.Arguments)
{
var argument = invocationExpression.Arguments[index];

if (argument != null && currentUICultureProperty != null &&
installedUICultureProperty != null && currentThreadCurrentUICultureProperty != null)
if (!iformatProviderType.Equals(argument.Parameter?.Type))
{
var semanticModel = argument.SemanticModel!;

var symbol = semanticModel.GetSymbolInfo(argument.Value.Syntax, oaContext.CancellationToken).Symbol;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mavasani I assume semantic model calls are more expensive than getting info directly from IOperation?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely.

continue;
}

if (symbol != null &&
if (currentUICultureProperty != null && installedUICultureProperty != null && currentThreadCurrentUICultureProperty != null)
{
if (argument.Value.WalkDownConversion() is IPropertyReferenceOperation { Property: { } symbol } &&
(symbol.Equals(currentUICultureProperty) ||
symbol.Equals(installedUICultureProperty) ||
symbol.Equals(currentThreadCurrentUICultureProperty) ||
Expand Down Expand Up @@ -324,14 +321,6 @@ static IEnumerable<IMethodSymbol> GetToStringMethods(INamedTypeSymbol namedTypeS
=> namedTypeSymbol.GetMembers("ToString").OfType<IMethodSymbol>().WhereNotNull();
}

private static IEnumerable<int> GetIndexesOfParameterType(IMethodSymbol targetMethod, INamedTypeSymbol formatProviderType)
{
return targetMethod.Parameters
.Select((Parameter, Index) => (Parameter, Index))
.Where(x => x.Parameter.Type.Equals(formatProviderType))
.Select(x => x.Index);
}
Comment on lines -327 to -333
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now looping over arguments directly and than checking if the parameter is of interest. The new implementation should hopefully be more performant and more straightforward.


private static ParameterInfo GetParameterInfo(INamedTypeSymbol type, bool isArray = false, int arrayRank = 0, bool isParams = false)
{
return ParameterInfo.GetParameterInfo(type, isArray, arrayRank, isParams);
Expand Down