From 9a936b9fe58b18a233ae27c642640185a721f71c Mon Sep 17 00:00:00 2001 From: stakx Date: Tue, 13 Oct 2020 23:36:07 +0200 Subject: [PATCH] More precise check for anonymous types ...since not all compiler-generated types are anonymous types. --- src/Moq/Linq/MockSetupsBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Moq/Linq/MockSetupsBuilder.cs b/src/Moq/Linq/MockSetupsBuilder.cs index bf02c5bf3..328c5010f 100644 --- a/src/Moq/Linq/MockSetupsBuilder.cs +++ b/src/Moq/Linq/MockSetupsBuilder.cs @@ -151,7 +151,7 @@ private sealed class ReplaceMockObjectWithParameter : ExpressionVisitor protected override Expression VisitMember(MemberExpression node) { - if (node.Expression is ParameterExpression pe && pe.Type.IsDefined(typeof(CompilerGeneratedAttribute))) + if (node.Expression is ParameterExpression pe && pe.Type.IsDefined(typeof(CompilerGeneratedAttribute)) && pe.Type.Name.Contains("f__AnonymousType")) { // In LINQ query expressions with more than one `from` clause such as: //