Skip to content

Commit

Permalink
Add test coverage for AttributeCollection, fix bugs and nullable anno…
Browse files Browse the repository at this point in the history
…tate (#36118)

* Add test coverage for AttributeCollection and fix bugs

* PR Feedback
  • Loading branch information
hughbe authored Oct 12, 2020
1 parent 671f99b commit 94c6054
Show file tree
Hide file tree
Showing 3 changed files with 416 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public virtual Attribute this[Type attributeType]
{
get
{
if (attributeType == null)
{
throw new ArgumentNullException(nameof(attributeType));
}

lock (s_internalSyncObject)
{
// 2 passes here for perf. Really! first pass, we just
Expand Down Expand Up @@ -213,6 +218,11 @@ public virtual Attribute this[Type attributeType]
/// </summary>
public bool Contains(Attribute attribute)
{
if (attribute == null)
{
return false;
}

Attribute attr = this[attribute.GetType()];
return attr != null && attr.Equals(attribute);
}
Expand Down Expand Up @@ -245,6 +255,11 @@ public bool Contains(Attribute[] attributes)
/// </summary>
protected Attribute GetDefaultAttribute(Type attributeType)
{
if (attributeType == null)
{
throw new ArgumentNullException(nameof(attributeType));
}

lock (s_internalSyncObject)
{
if (s_defaultAttributes == null)
Expand Down Expand Up @@ -316,6 +331,11 @@ public bool Matches(Attribute attribute)
/// </summary>
public bool Matches(Attribute[] attributes)
{
if (attributes == null)
{
return true;
}

for (int i = 0; i < attributes.Length; i++)
{
if (!Matches(attributes[i]))
Expand All @@ -329,7 +349,7 @@ public bool Matches(Attribute[] attributes)

bool ICollection.IsSynchronized => false;

object ICollection.SyncRoot => null;
object ICollection.SyncRoot => this;

int ICollection.Count => Count;

Expand Down
Loading

0 comments on commit 94c6054

Please sign in to comment.