提交 f5bdc0b4 编写于 作者: J Jason Malinowski

Simplify IMethodSymbolExtensions.RemoveAttributesCore

We had a helper for 'create an IMethodSymbol with certain changes', but
it didn't have quite enough that we could use it in more places. Also
inline it into the single caller.
上级 8285c9e4
......@@ -428,7 +428,8 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList<ISymbol>
ImmutableArray<IParameterSymbol>? parameters = default,
ImmutableArray<SyntaxNode> statements = default,
INamedTypeSymbol containingType = null,
ITypeSymbol returnType = null)
ITypeSymbol returnType = null,
Optional<ImmutableArray<AttributeData>> returnTypeAttributes = default)
{
return CreateMethodSymbol(
containingType,
......@@ -442,7 +443,7 @@ public static INamespaceSymbol CreateNamespaceSymbol(string name, IList<ISymbol>
method.TypeParameters,
parameters ?? method.Parameters,
statements,
returnTypeAttributes: method.GetReturnTypeAttributes());
returnTypeAttributes: returnTypeAttributes.HasValue ? returnTypeAttributes.Value : method.GetReturnTypeAttributes());
}
internal static IPropertySymbol CreatePropertySymbol(
......
......@@ -208,16 +208,6 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis
bool shouldRemoveAttribute(AttributeData a) =>
removeAttributeTypes.Any(attr => attr != null && attr.Equals(a.AttributeClass)) || !a.AttributeClass.IsAccessibleWithin(accessibleWithin);
return method.RemoveAttributesCore(
shouldRemoveAttribute,
statements: default,
handlesExpressions: default);
}
private static IMethodSymbol RemoveAttributesCore(
this IMethodSymbol method, Func<AttributeData, bool> shouldRemoveAttribute,
ImmutableArray<SyntaxNode> statements, ImmutableArray<SyntaxNode> handlesExpressions)
{
var methodHasAttribute = method.GetAttributes().Any(shouldRemoveAttribute);
var someParameterHasAttribute = method.Parameters
......@@ -231,23 +221,16 @@ public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ILis
}
return CodeGenerationSymbolFactory.CreateMethodSymbol(
method.ContainingType,
method.GetAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)),
method.DeclaredAccessibility,
method.GetSymbolModifiers(),
method.ReturnType,
method.RefKind,
method.ExplicitInterfaceImplementations,
method.Name,
method.TypeParameters,
method.Parameters.SelectAsArray(p =>
method,
containingType: method.ContainingType,
explicitInterfaceImplementations: method.ExplicitInterfaceImplementations,
attributes: method.GetAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)),
parameters: method.Parameters.SelectAsArray(p =>
CodeGenerationSymbolFactory.CreateParameterSymbol(
p.GetAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)),
p.RefKind, p.IsParams, p.Type, p.Name, p.IsOptional,
p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)),
statements,
handlesExpressions,
method.GetReturnTypeAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)));
returnTypeAttributes: method.GetReturnTypeAttributes().WhereAsArray(a => !shouldRemoveAttribute(a)));
}
public static bool? IsMoreSpecificThan(this IMethodSymbol method1, IMethodSymbol method2)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册