Skip to content

Commit

Permalink
Upmerge fixes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Nov 9, 2024
2 parents f750734 + c6cd85c commit f7aec45
Show file tree
Hide file tree
Showing 24 changed files with 275 additions and 279 deletions.
1 change: 1 addition & 0 deletions Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class Build : NukeBuild
ReportTypes.lcov,
ReportTypes.HtmlInline_AzurePipelines_Dark)
.AddFileFilters("-*.g.cs")
.AddFileFilters("-*.nuget*")
.SetAssemblyFilters("+FluentAssertions"));

string link = TestResultsDirectory / "reports" / "index.html";
Expand Down
4 changes: 2 additions & 2 deletions FluentAssertions.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=012E3B0572DEF2448B0B5D9AA88E6210/Shortcut/@EntryValue">aaa</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=012E3B0572DEF2448B0B5D9AA88E6210/Description/@EntryValue">Arrange-Act-Assert</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=012E3B0572DEF2448B0B5D9AA88E6210/Text/@EntryValue">[Fact]
public void $END$()
public void $Fact$()
{
// Arrange

$END$

// Act

Expand Down
29 changes: 3 additions & 26 deletions Src/FluentAssertions/Common/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using FluentAssertions.Equivalency;
using Reflectify;

namespace FluentAssertions.Common;

Expand All @@ -22,9 +23,6 @@ internal static class TypeExtensions
private static readonly ConcurrentDictionary<Type, bool> TypeIsRecordCache = new();
private static readonly ConcurrentDictionary<Type, bool> TypeIsCompilerGeneratedCache = new();

private static readonly ConcurrentDictionary<(Type Type, MemberVisibility Visibility), TypeMemberReflector>
TypeMemberReflectorsCache = new();

public static bool IsDecoratedWith<TAttribute>(this Type type)
where TAttribute : Attribute
{
Expand Down Expand Up @@ -184,7 +182,7 @@ public static bool OverridesEquals(this Type type)
/// </returns>
public static PropertyInfo FindProperty(this Type type, string propertyName, MemberVisibility memberVisibility)
{
var properties = type.GetProperties(memberVisibility);
var properties = type.GetProperties(memberVisibility.ToMemberKind());

return Array.Find(properties, p =>
p.Name == propertyName || p.Name.EndsWith("." + propertyName, StringComparison.Ordinal));
Expand All @@ -198,32 +196,11 @@ public static PropertyInfo FindProperty(this Type type, string propertyName, Mem
/// </returns>
public static FieldInfo FindField(this Type type, string fieldName, MemberVisibility memberVisibility)
{
var fields = type.GetFields(memberVisibility);
var fields = type.GetFields(memberVisibility.ToMemberKind());

return Array.Find(fields, p => p.Name == fieldName);
}

public static MemberInfo[] GetMembers(this Type typeToReflect, MemberVisibility visibility)
{
return GetTypeReflectorFor(typeToReflect, visibility).Members;
}

public static PropertyInfo[] GetProperties(this Type typeToReflect, MemberVisibility visibility)
{
return GetTypeReflectorFor(typeToReflect, visibility).Properties;
}

public static FieldInfo[] GetFields(this Type typeToReflect, MemberVisibility visibility)
{
return GetTypeReflectorFor(typeToReflect, visibility).Fields;
}

private static TypeMemberReflector GetTypeReflectorFor(Type typeToReflect, MemberVisibility visibility)
{
return TypeMemberReflectorsCache.GetOrAdd((typeToReflect, visibility),
static key => new TypeMemberReflector(key.Type, key.Visibility));
}

/// <summary>
/// Check if the type is declared as abstract.
/// </summary>
Expand Down
169 changes: 0 additions & 169 deletions Src/FluentAssertions/Common/TypeMemberReflector.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public IMember Match(IMember expectedMember, object subject, INode parent, IEqui
{
PropertyInfo propertyInfo = subject.GetType().FindProperty(
expectedMember.Name,
options.IncludedProperties | MemberVisibility.ExplicitlyImplemented);
options.IncludedProperties | MemberVisibility.ExplicitlyImplemented | MemberVisibility.DefaultInterfaceProperties);

subjectMember = propertyInfo is not null && !propertyInfo.IsIndexer() ? new Property(propertyInfo, parent) : null;
}
Expand Down
3 changes: 2 additions & 1 deletion Src/FluentAssertions/Equivalency/MemberVisibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public enum MemberVisibility
None = 0,
Internal = 1,
Public = 2,
ExplicitlyImplemented = 4
ExplicitlyImplemented = 4,
DefaultInterfaceProperties = 8
}
43 changes: 43 additions & 0 deletions Src/FluentAssertions/Equivalency/MemberVisibilityExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Concurrent;
using Reflectify;

namespace FluentAssertions.Equivalency;

internal static class MemberVisibilityExtensions
{
private static readonly ConcurrentDictionary<MemberVisibility, MemberKind> Cache = new();

public static MemberKind ToMemberKind(this MemberVisibility visibility)
{
return Cache.GetOrAdd(visibility, static v =>
{
MemberKind result = MemberKind.None;

#if NET6_0_OR_GREATER
var flags = Enum.GetValues<MemberVisibility>();
#else
var flags = (MemberVisibility[])Enum.GetValues(typeof(MemberVisibility));
#endif
foreach (MemberVisibility flag in flags)
{
if (v.HasFlag(flag))
{
var convertedFlag = flag switch
{
MemberVisibility.None => MemberKind.None,
MemberVisibility.Internal => MemberKind.Internal,
MemberVisibility.Public => MemberKind.Public,
MemberVisibility.ExplicitlyImplemented => MemberKind.ExplicitlyImplemented,
MemberVisibility.DefaultInterfaceProperties => MemberKind.DefaultInterfaceProperties,
_ => throw new ArgumentOutOfRangeException(nameof(v), v, null)
};

result |= convertedFlag;
}
}

return result;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using FluentAssertions.Common;
using Reflectify;

namespace FluentAssertions.Equivalency.Selection;

Expand All @@ -15,7 +15,7 @@ public IEnumerable<IMember> SelectMembers(INode currentNode, IEnumerable<IMember
MemberSelectionContext context)
{
IEnumerable<IMember> selectedFields = context.Type
.GetFields(context.IncludedFields)
.GetFields(context.IncludedFields.ToMemberKind())
.Select(info => new Field(info, currentNode));

return selectedMembers.Union(selectedFields).ToList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using FluentAssertions.Common;
using Reflectify;

namespace FluentAssertions.Equivalency.Selection;

Expand All @@ -14,8 +14,11 @@ internal class AllPropertiesSelectionRule : IMemberSelectionRule
public IEnumerable<IMember> SelectMembers(INode currentNode, IEnumerable<IMember> selectedMembers,
MemberSelectionContext context)
{
MemberVisibility visibility = context.IncludedProperties | MemberVisibility.ExplicitlyImplemented |
MemberVisibility.DefaultInterfaceProperties;

IEnumerable<IMember> selectedProperties = context.Type
.GetProperties(context.IncludedProperties)
.GetProperties(visibility.ToMemberKind())
.Select(info => new Property(context.Type, info, currentNode));

return selectedMembers.Union(selectedProperties).ToList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Reflection;
using FluentAssertions.Common;
using Reflectify;

namespace FluentAssertions.Equivalency.Selection;

Expand All @@ -21,7 +22,7 @@ public IncludeMemberByPathSelectionRule(MemberPath pathToInclude)
protected override void AddOrRemoveMembersFrom(List<IMember> selectedMembers, INode parent, string parentPath,
MemberSelectionContext context)
{
foreach (MemberInfo memberInfo in context.Type.GetMembers(MemberVisibility.Public | MemberVisibility.Internal))
foreach (MemberInfo memberInfo in context.Type.GetMembers(MemberKind.Public | MemberKind.Internal))
{
var memberPath = new MemberPath(context.Type, memberInfo.DeclaringType, parentPath.Combine(memberInfo.Name));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq.Expressions;
using System.Reflection;
using FluentAssertions.Common;
using Reflectify;

namespace FluentAssertions.Equivalency.Selection;

Expand All @@ -27,8 +28,8 @@ public IEnumerable<IMember> SelectMembers(INode currentNode, IEnumerable<IMember
{
var members = new List<IMember>(selectedMembers);

foreach (MemberInfo memberInfo in currentNode.Type.GetMembers(MemberVisibility.Public |
MemberVisibility.Internal))
foreach (MemberInfo memberInfo in currentNode.Type.GetMembers(MemberKind.Public |
MemberKind.Internal))
{
IMember member = MemberFactory.Create(memberInfo, currentNode);

Expand Down
Loading

0 comments on commit f7aec45

Please sign in to comment.