Skip to content

Commit

Permalink
Optimize IsRecord()
Browse files Browse the repository at this point in the history
`<Clone>$` is an "unspeakable" method name generated by Roslyn, which should be sufficient to determine if a type is a record.
  • Loading branch information
jnyrup committed Dec 30, 2022
1 parent 6a03535 commit 7e3d9f5
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions Src/FluentAssertions/Common/TypeExtensions.cs
Expand Up @@ -583,13 +583,7 @@ 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 TypeIsRecordCache.GetOrAdd(type, static t => t.GetMethod("<Clone>$") is not null);
}

private static bool IsKeyValuePair(Type type)
Expand Down

0 comments on commit 7e3d9f5

Please sign in to comment.