Skip to content

Commit c8a06f5

Browse files
committed
Avoid while(true)
1 parent 33f20f8 commit c8a06f5

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/NHibernate/Util/ExpressionsHelper.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,12 @@ private static bool TraverseMembers(
192192
{
193193
// Traverse the members that were traversed by the TryGetAllMemberMetadata method in the reverse order and try to keep
194194
// tracking the entity persister until all members are traversed.
195-
System.Type convertType;
196195
var member = memberPaths.Pop();
197196
var currentType = currentEntityPersister.EntityMetamodel.GetPropertyType(member.Path);
198197
IAbstractComponentType currentComponentType = null;
199-
while (true)
198+
while (memberPaths.Count > 0 && currentType != null)
200199
{
201-
// When traversed to the top of the expression, return the current tracking values
202-
if (memberPaths.Count == 0)
203-
{
204-
memberPath = currentEntityPersister != null || currentComponentType != null ? member.Path : null;
205-
mappedType = GetType(currentEntityPersister, currentType, member, sessionFactory, out _);
206-
entityPersister = currentEntityPersister;
207-
component = currentComponentType;
208-
return mappedType != null;
209-
}
210-
211-
if (currentType == null) // Member not mapped
212-
{
213-
memberPath = null;
214-
mappedType = null;
215-
entityPersister = null;
216-
component = null;
217-
return false;
218-
}
219-
220-
convertType = member.ConvertType;
200+
var convertType = member.ConvertType;
221201
// Concatenate the component property path in order to be able to use EntityMetamodel.GetPropertyType to retrieve the type.
222202
// As GetPropertyType supports only components, do not concatenate when dealing with collection composite elements or elements.
223203
if (!currentType.IsAnyType && currentType is IAbstractComponentType)
@@ -256,6 +236,23 @@ private static bool TraverseMembers(
256236
break;
257237
}
258238
}
239+
240+
// When traversed to the top of the expression, return the current tracking values
241+
if (memberPaths.Count == 0)
242+
{
243+
memberPath = currentEntityPersister != null || currentComponentType != null ? member.Path : null;
244+
mappedType = GetType(currentEntityPersister, currentType, member, sessionFactory, out _);
245+
entityPersister = currentEntityPersister;
246+
component = currentComponentType;
247+
return mappedType != null;
248+
}
249+
250+
// Member not mapped
251+
memberPath = null;
252+
mappedType = null;
253+
entityPersister = null;
254+
component = null;
255+
return false;
259256
}
260257

261258
private static void ProcessComponentType(

0 commit comments

Comments
 (0)