Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public class Constructors : Filtered<ConstructorInfo, Constructors>, IDescribabl
/// Container for a filterable collection of <see cref="ConstructorInfo" />.
/// </summary>
internal Constructors(Types types, string description) : base(types.SelectMany(type =>
type.GetConstructors(BindingFlags.DeclaredOnly |
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.Static)))
type.GetDeclaredConstructors()))
{
_types = types;
_description = description;
Expand Down
5 changes: 1 addition & 4 deletions Source/aweXpect.Reflection/Collections/Filtered.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public class Events : Filtered<EventInfo, Events>, IDescribableSubject
/// Container for a filterable collection of <see cref="EventInfo" />.
/// </summary>
internal Events(Types types, string description) : base(types.SelectMany(type =>
type.GetEvents(BindingFlags.DeclaredOnly |
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance)))
type.GetDeclaredEvents()))
{
_types = types;
_description = description;
Expand Down
6 changes: 1 addition & 5 deletions Source/aweXpect.Reflection/Collections/Filtered.Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public class Fields : Filtered<FieldInfo, Fields>, IDescribableSubject
/// Container for a filterable collection of <see cref="FieldInfo" />.
/// </summary>
internal Fields(Types types, string description) : base(types.SelectMany(type =>
type.GetFields(BindingFlags.DeclaredOnly |
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.Static)))
type.GetDeclaredFields()))
{
_types = types;
_description = description;
Expand Down
6 changes: 1 addition & 5 deletions Source/aweXpect.Reflection/Collections/Filtered.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public class Methods : Filtered<MethodInfo, Methods>, IDescribableSubject
/// Container for a filterable collection of <see cref="MethodInfo" />.
/// </summary>
internal Methods(Types types, string description) : base(types.SelectMany(type =>
type.GetMethods(BindingFlags.DeclaredOnly |
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.Static)))
type.GetDeclaredMethods()))
{
_types = types;
_description = description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public class Properties : Filtered<PropertyInfo, Properties>, IDescribableSubjec
/// Container for a filterable collection of <see cref="PropertyInfo" />.
/// </summary>
internal Properties(Types types, string description) : base(types.SelectMany(type =>
type.GetProperties(BindingFlags.DeclaredOnly |
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.Static)))
type.GetDeclaredProperties()))
{
_types = types;
_description = description;
Expand Down
11 changes: 11 additions & 0 deletions Source/aweXpect.Reflection/Helpers/TypeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public static ConstructorInfo[] GetDeclaredConstructors(
BindingFlags.Instance |
BindingFlags.Static);

/// <summary>
/// Searches for events in the <paramref name="type" /> that were directly declared there.
/// </summary>
public static EventInfo[] GetDeclaredEvents(
this Type type)
=> type
.GetEvents(BindingFlags.DeclaredOnly |
BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance);

/// <summary>
/// Searches for fields in the <paramref name="type" /> that were directly declared there.
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions Tests/aweXpect.Reflection.Tests/InTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ await That(sut).HasSingle().Which
await That(sut.GetDescription()).IsEqualTo("in executing assembly");
}

[Fact]
public async Task Fields_ShouldExcludeCompilerGeneratedBackingFields()
{
Filtered.Fields fields = In.Type<ClassWithMembers>().Fields();

await That(fields).All().Satisfy(field => !field.Name.EndsWith("__BackingField")).And.IsNotEmpty();
}

[Fact]
public async Task Methods_ShouldExcludeCompilerGeneratedAccessors()
{
Filtered.Methods methods = In.Type<ClassWithMembers>().Methods();

await That(methods).All().Satisfy(method => !method.IsSpecialName).And.IsNotEmpty();
}

[Fact]
public async Task Type_WithGenericParameter_ShouldIncludeSpecifiedType()
{
Expand Down Expand Up @@ -165,6 +181,14 @@ await That(sut.GetDescription())
$"in types [{nameof(InTests)}, {nameof(InternalClass)}, {nameof(PublicClass)}, {nameof(AccessModifiers)}]");
}

private sealed class ClassWithMembers
{
public readonly int Field = 1;
public int Property { get; set; }

public int Method() => Field + Property;
}

private sealed class ThrowingAssembly(Type?[] loadableTypes) : Assembly
{
public override string FullName => nameof(ThrowingAssembly);
Expand Down
Loading