Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify NotNullIfParameterNotNull implementation in PEParameterSymbol #51995

Merged
merged 4 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
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 @@ -706,20 +706,7 @@ internal override ImmutableHashSet<string> NotNullIfParameterNotNull
{
get
{
var attributes = GetAttributes();
var result = ImmutableHashSet<string>.Empty;
foreach (var attribute in attributes)
{
if (attribute.IsTargetAttribute(this, AttributeDescription.NotNullIfNotNullAttribute))
{
if (attribute.DecodeNotNullIfNotNullAttribute() is string parameterName)
{
result = result.Add(parameterName);
}
}
}

return result;
return _moduleSymbol.Module.GetStringValuesOfNotNullIfNotNullAttribute(_handle);
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/Compilers/Core/Portable/MetadataReader/PEModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,27 @@ internal bool HasMaybeNullWhenOrNotNullWhenOrDoesNotReturnIfAttribute(EntityHand
return false;
}

internal ImmutableHashSet<string> GetStringValuesOfNotNullIfNotNullAttribute(EntityHandle token)
{
var attributeInfos = FindTargetAttributes(token, AttributeDescription.NotNullIfNotNullAttribute);
333fred marked this conversation as resolved.
Show resolved Hide resolved

var result = ImmutableHashSet<string>.Empty;
if (attributeInfos is null)
{
return result;
}

foreach (var attributeInfo in attributeInfos)
{
if (TryExtractStringValueFromAttribute(attributeInfo.Handle, out string parameterName))
{
result = result.Add(parameterName);
333fred marked this conversation as resolved.
Show resolved Hide resolved
}
}

return result;
}

internal CustomAttributeHandle GetAttributeUsageAttributeHandle(EntityHandle token)
{
AttributeInfo info = FindTargetAttribute(token, AttributeDescription.AttributeUsageAttribute);
Expand Down