Skip to content

Commit

Permalink
Simplify NotNullIfParameterNotNull implementation in PEParameterSymbol (
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 authored Mar 23, 2021
1 parent b47625a commit 7becc52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
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);

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);
}
}

return result;
}

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

0 comments on commit 7becc52

Please sign in to comment.