Skip to content

Commit

Permalink
Make everything internal and added extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Oct 28, 2024
1 parent 1450dbb commit dbfac28
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/Reflectify/Reflectify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -55,7 +55,7 @@ private static Reflector GetFor(Type typeToReflect, MemberKind kind)
}
}

public static class PropertyInfoExtensions
internal static class PropertyInfoExtensions
{
/// <summary>
/// Returns <c>true</c> if the property is an indexer, or <c>false</c> otherwise.
Expand Down Expand Up @@ -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.
/// </summary>
[Flags]
public enum MemberKind
internal enum MemberKind
{
None,
Public = 1,
Internal = 2,
ExplicitlyImplemented = 4,
Expand Down
8 changes: 7 additions & 1 deletion src/Reflectify/Reflectify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
<DefineConstants>REFLECTIFY_COMPILE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ItemGroup Label="Internals visible to">
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Reflectify.Specs</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\Reflectify.xml</DocumentationFile>
</PropertyGroup>

Expand Down
31 changes: 23 additions & 8 deletions tests/Reflectify.Specs/TypeExtensionsSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Globalization;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using JetBrains.Annotations;
using Xunit;
Expand All @@ -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
Expand Down Expand Up @@ -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) }
});
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dbfac28

Please sign in to comment.