Skip to content

Commit

Permalink
Merge pull request #2080 from jnyrup/IsRecord
Browse files Browse the repository at this point in the history
Optimize `IsRecord()`
  • Loading branch information
jnyrup committed Jan 1, 2023
2 parents 10ae57e + 5117eac commit ca5c660
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Src/FluentAssertions/Common/TypeExtensions.cs
Expand Up @@ -588,12 +588,12 @@ private static bool IsAnonymousType(this Type type)
public static bool IsRecord(this Type type)
{
return TypeIsRecordCache.GetOrAdd(type, static t =>
t.GetMethod("<Clone>$") is not null &&
t.GetTypeInfo()
.DeclaredProperties
.FirstOrDefault(p => p.Name == "EqualityContract")?
.GetMethod?
.GetCustomAttribute(typeof(CompilerGeneratedAttribute)) is not null);
{
return t.GetMethod("<Clone>$", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) is { } &&
t.GetProperty("EqualityContract", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)?
.GetMethod?
.GetCustomAttribute(typeof(CompilerGeneratedAttribute)) is { };
});
}

private static bool IsKeyValuePair(Type type)
Expand Down

0 comments on commit ca5c660

Please sign in to comment.