Skip to content

Commit 9eb787a

Browse files
committed
TypeHelper: Small improvements
1 parent 83cb772 commit 9eb787a

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

Orm/Xtensive.Orm/Reflection/TypeHelper.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,17 +1137,22 @@ internal static MemberInfo[] TryGetFieldInfoFromClosure(this Type closureType, T
11371137

11381138
// new closure types structure with extra layer of complesity
11391139
// where there is a field with name like 'CS$8__locals1' as actual variables storage.
1140-
var localsContainerFields = closureTypeFields.Where(f => f.Name.Contains("_locals", StringComparison.Ordinal) && f.FieldType.IsClosure()).ToList();
1140+
var localsContainerFields = closureTypeFields.Where(f => f.Name.Contains("_locals", StringComparison.Ordinal) && f.FieldType.IsClosure()).ToChainedBuffer();
11411141
if (localsContainerFields.Count == 0) {
11421142
return null;
11431143
}
1144-
var candidates = new List<(MemberInfo, MemberInfo)>();
1144+
1145+
MemberInfo[] memberCallChain = null;
11451146
foreach (var f in localsContainerFields) {
1146-
var result = f.FieldType.GetFields().FirstOrDefault(field => field.FieldType == fieldType);
1147-
if (result != null)
1148-
candidates.Add((f, result));
1147+
var nestedField = f.FieldType.GetFields().FirstOrDefault(field => field.FieldType == fieldType);
1148+
if (nestedField != null) {
1149+
if (memberCallChain == null)
1150+
memberCallChain = new[] { f, nestedField };
1151+
else
1152+
return null;
1153+
}
11491154
}
1150-
return candidates.Count == 1 ? new[] { candidates[0].Item1, candidates[0].Item2 } : null;
1155+
return memberCallChain;
11511156
}
11521157

11531158
private static string TrimGenericSuffix(string @string)

0 commit comments

Comments
 (0)