diff --git a/src/Reflectify/Reflectify.cs b/src/Reflectify/Reflectify.cs index 2c0c789..ee19bd1 100644 --- a/src/Reflectify/Reflectify.cs +++ b/src/Reflectify/Reflectify.cs @@ -13,7 +13,7 @@ namespace Reflectify; -public static class TypeExtensions +internal static class TypeExtensions { private static readonly ConcurrentDictionary<(Type Type, MemberKind Kind), Reflector> ReflectorCache = new(); @@ -55,7 +55,7 @@ private static Reflector GetFor(Type typeToReflect, MemberKind kind) } } -public static class PropertyInfoExtensions +internal static class PropertyInfoExtensions { /// /// Returns true if the property is an indexer, or false otherwise. @@ -83,8 +83,9 @@ public static bool IsExplicitlyImplemented(this PropertyInfo prop) /// Defines the kinds of members you want to get when querying for the fields and properties of a type. /// [Flags] -public enum MemberKind +internal enum MemberKind { + None, Public = 1, Internal = 2, ExplicitlyImplemented = 4, diff --git a/src/Reflectify/Reflectify.csproj b/src/Reflectify/Reflectify.csproj index 376e9b8..f5a3e35 100644 --- a/src/Reflectify/Reflectify.csproj +++ b/src/Reflectify/Reflectify.csproj @@ -10,7 +10,13 @@ REFLECTIFY_COMPILE - + + + <_Parameter1>Reflectify.Specs + + + + bin\Debug\Reflectify.xml diff --git a/tests/Reflectify.Specs/TypeExtensionsSpecs.cs b/tests/Reflectify.Specs/TypeExtensionsSpecs.cs index 495cdb2..9a26ff1 100644 --- a/tests/Reflectify.Specs/TypeExtensionsSpecs.cs +++ b/tests/Reflectify.Specs/TypeExtensionsSpecs.cs @@ -1,6 +1,4 @@ using System.Globalization; -using System.Linq; -using System.Reflection; using FluentAssertions; using JetBrains.Annotations; using Xunit; @@ -26,7 +24,8 @@ public void Can_get_all_public_explicit_and_default_interface_properties() new { Name = "InterfaceProperty", PropertyType = typeof(string) }, new { - Name = $"{typeof(IInterfaceWithSingleProperty).FullName!.Replace("+", ".")}.ExplicitlyImplementedProperty", + Name = + $"{typeof(IInterfaceWithSingleProperty).FullName!.Replace("+", ".")}.ExplicitlyImplementedProperty", PropertyType = typeof(string) }, #if NETCOREAPP3_0_OR_GREATER @@ -95,11 +94,7 @@ public void Prefers_normal_property_over_explicitly_implemented_one() // Assert properties.Should().BeEquivalentTo(new[] { - new - { - Name = "ExplicitlyImplementedProperty", - PropertyType = typeof(int) - } + new { Name = "ExplicitlyImplementedProperty", PropertyType = typeof(int) } }); } @@ -144,6 +139,16 @@ public void Will_ignore_indexers() new { Name = "Foo", PropertyType = typeof(object) } }); } + + [Fact] + public void Supports_returning_nothing_if_asked_for() + { + // Act + var properties = typeof(ClassWithIndexer).GetProperties(MemberKind.None); + + // Assert + properties.Should().BeEmpty(); + } } public class GetFields @@ -190,6 +195,16 @@ public void Can_find_all_fields() new { Name = "ProtectedInternalField", FieldType = typeof(string) } }); } + + [Fact] + public void Supports_returning_nothing_if_asked_for() + { + // Act + var properties = typeof(ClassWithIndexer).GetFields(MemberKind.None); + + // Assert + properties.Should().BeEmpty(); + } } public class GetMembers