From a0c67d2b0d9f8a0471df482fad606ec70912d55e Mon Sep 17 00:00:00 2001 From: Jonas Nyrup Date: Sat, 23 Nov 2024 20:19:55 +0100 Subject: [PATCH] Use return value of HashSet.Add --- src/Reflectify/Reflectify.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Reflectify/Reflectify.cs b/src/Reflectify/Reflectify.cs index b0ed6e9..29d60bc 100644 --- a/src/Reflectify/Reflectify.cs +++ b/src/Reflectify/Reflectify.cs @@ -635,11 +635,10 @@ private void AddNormalProperties(MemberKind kind, PropertyInfo[] allProperties) { foreach (var property in allProperties) { - if (!collectedPropertyNames.Contains(property.Name) && !property.IsExplicitlyImplemented() && - HasVisibility(kind, property)) + if (HasVisibility(kind, property) && !property.IsExplicitlyImplemented() && + collectedPropertyNames.Add(property.Name)) { selectedProperties.Add(property); - collectedPropertyNames.Add(property.Name); } } } @@ -661,10 +660,9 @@ private void AddExplicitlyImplementedProperties(MemberKind kind, PropertyInfo[] { var name = p.Name.Split('.').Last(); - if (!collectedPropertyNames.Contains(name)) + if (collectedPropertyNames.Add(name)) { selectedProperties.Add(p); - collectedPropertyNames.Add(name); } } } @@ -681,11 +679,10 @@ private void AddInterfaceProperties(Type typeToReflect, MemberKind kind, Binding { foreach (var prop in interfaceType.GetProperties(flags)) { - if (!collectedPropertyNames.Contains(prop.Name) && - (!prop.IsAbstract() || typeToReflect.IsInterface)) + if ((!prop.IsAbstract() || typeToReflect.IsInterface) && + collectedPropertyNames.Add(prop.Name)) { selectedProperties.Add(prop); - collectedPropertyNames.Add(prop.Name); } } } @@ -703,10 +700,9 @@ private void LoadFields(Type typeToReflect, MemberKind kind) foreach (var field in files) { - if (!collectedFieldNames.Contains(field.Name) && HasVisibility(kind, field)) + if (HasVisibility(kind, field) && collectedFieldNames.Add(field.Name)) { selectedFields.Add(field); - collectedFieldNames.Add(field.Name); } }