Skip to content

Commit

Permalink
Check if fullName is null
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanLiu90 committed Sep 20, 2023
1 parent 540ed8f commit fa447d1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/DotNet/CustomAttributeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public CustomAttributeCollection(int length, object context, Func<object, int, C
/// </summary>
/// <param name="fullName">Full name of custom attribute type that should be removed</param>
public void RemoveAll(string fullName) {
if (fullName == null)
return;

for (int i = Count - 1; i >= 0; i--) {
var ca = this[i];
if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName)
Expand All @@ -50,6 +53,9 @@ public void RemoveAll(string fullName) {
/// <param name="fullName">Full name of custom attribute type</param>
/// <returns>A <see cref="CustomAttribute"/> or <c>null</c> if it wasn't found</returns>
public CustomAttribute Find(string fullName) {
if (fullName == null)
return null;

foreach (var ca in this) {
if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName)
return ca;
Expand All @@ -64,6 +70,9 @@ public CustomAttribute Find(string fullName) {
/// <param name="fullName">Full name of custom attribute type</param>
/// <returns>All <see cref="CustomAttribute"/>s of the requested type</returns>
public IEnumerable<CustomAttribute> FindAll(string fullName) {
if (fullName == null)
yield break;

foreach (var ca in this) {
if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName)
yield return ca;
Expand Down

0 comments on commit fa447d1

Please sign in to comment.