Skip to content

Commit 051a7ad

Browse files
committed
EmptyData: fix IEnumerator disposal
1 parent f7d63d9 commit 051a7ad

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Framework/Framework/Controls/EmptyData.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext
5252
var dataSourceBinding = GetValueBinding(DataSourceProperty);
5353
TagName = WrapperTagName;
5454
// if DataSource is resource binding && DataSource is not empty then don't render anything
55-
if (dataSourceBinding is {} || GetIEnumerableFromDataSource()?.GetEnumerator()?.MoveNext() != true)
55+
if (dataSourceBinding is {} || Any(GetIEnumerableFromDataSource()))
5656
{
5757
if (dataSourceBinding is {})
5858
{
@@ -68,5 +68,14 @@ protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext
6868
base.RenderControl(writer, context);
6969
}
7070
}
71+
72+
private static bool Any(System.Collections.IEnumerable? enumerable)
73+
{
74+
if (enumerable is null)
75+
return false;
76+
var enumerator = enumerable.GetEnumerator();
77+
using (enumerator as IDisposable)
78+
return enumerator.MoveNext();
79+
}
7180
}
7281
}

0 commit comments

Comments
 (0)