diff --git a/Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj b/Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj
index b7bd8631cf82..433791d166cf 100644
--- a/Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj
+++ b/Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj
@@ -32,7 +32,7 @@
portable
-
+
diff --git a/Algorithm.Framework/QuantConnect.Algorithm.Framework.csproj b/Algorithm.Framework/QuantConnect.Algorithm.Framework.csproj
index 54f4584ee303..dc7e4d657f6a 100644
--- a/Algorithm.Framework/QuantConnect.Algorithm.Framework.csproj
+++ b/Algorithm.Framework/QuantConnect.Algorithm.Framework.csproj
@@ -29,7 +29,7 @@
LICENSE
-
+
diff --git a/Algorithm/QuantConnect.Algorithm.csproj b/Algorithm/QuantConnect.Algorithm.csproj
index 075a3562f02c..fa6bf11feda6 100644
--- a/Algorithm/QuantConnect.Algorithm.csproj
+++ b/Algorithm/QuantConnect.Algorithm.csproj
@@ -29,7 +29,7 @@
LICENSE
-
+
diff --git a/AlgorithmFactory/QuantConnect.AlgorithmFactory.csproj b/AlgorithmFactory/QuantConnect.AlgorithmFactory.csproj
index f6a81f885b6b..d3a589b2cd12 100644
--- a/AlgorithmFactory/QuantConnect.AlgorithmFactory.csproj
+++ b/AlgorithmFactory/QuantConnect.AlgorithmFactory.csproj
@@ -28,7 +28,7 @@
LICENSE
-
+
diff --git a/Common/QuantConnect.csproj b/Common/QuantConnect.csproj
index 7ca0ae0d4e80..a57fb319eeb4 100644
--- a/Common/QuantConnect.csproj
+++ b/Common/QuantConnect.csproj
@@ -35,7 +35,7 @@
-
+
diff --git a/Common/Util/MemoizingEnumerable.cs b/Common/Util/MemoizingEnumerable.cs
index 041eea4f34e4..c7ec97cf4a67 100644
--- a/Common/Util/MemoizingEnumerable.cs
+++ b/Common/Util/MemoizingEnumerable.cs
@@ -14,6 +14,7 @@
*
*/
+using System;
using System.Collections;
using System.Collections.Generic;
@@ -35,6 +36,25 @@ public class MemoizingEnumerable : IEnumerable
/// Should be called before the enumeration starts
public bool Enabled { get; set; }
+ ///
+ /// Gets the count of items in the enumerable. This will force enumeration of the entire collection if it has not already been enumerated.
+ ///
+ public int Count
+ {
+ get
+ {
+ if (!Enabled)
+ {
+ throw new InvalidOperationException("Count is not supported when memoization is disabled");
+ }
+ if (_buffer == null)
+ {
+ foreach (var item in this) {}
+ }
+ return _buffer.Count;
+ }
+ }
+
///
/// Initializes a new instance of the class
///
diff --git a/Engine/QuantConnect.Lean.Engine.csproj b/Engine/QuantConnect.Lean.Engine.csproj
index 48dafca8ddcc..e92072ac67c7 100644
--- a/Engine/QuantConnect.Lean.Engine.csproj
+++ b/Engine/QuantConnect.Lean.Engine.csproj
@@ -41,7 +41,7 @@
-
+
diff --git a/Indicators/QuantConnect.Indicators.csproj b/Indicators/QuantConnect.Indicators.csproj
index 0245ee927df5..cb22406cc1bb 100644
--- a/Indicators/QuantConnect.Indicators.csproj
+++ b/Indicators/QuantConnect.Indicators.csproj
@@ -31,7 +31,7 @@
-
+
diff --git a/Report/QuantConnect.Report.csproj b/Report/QuantConnect.Report.csproj
index f95f44a23d3b..71ec50a70f8c 100644
--- a/Report/QuantConnect.Report.csproj
+++ b/Report/QuantConnect.Report.csproj
@@ -39,7 +39,7 @@
LICENSE
-
+
diff --git a/Research/QuantConnect.Research.csproj b/Research/QuantConnect.Research.csproj
index 4cd1639da1f2..209c10acc35e 100644
--- a/Research/QuantConnect.Research.csproj
+++ b/Research/QuantConnect.Research.csproj
@@ -1,4 +1,4 @@
-
+
Debug
AnyCPU
@@ -34,7 +34,7 @@
-
+
diff --git a/Tests/Common/Util/MemoizingEnumerableTests.cs b/Tests/Common/Util/MemoizingEnumerableTests.cs
index a08b0910445d..4ba3946b9e34 100644
--- a/Tests/Common/Util/MemoizingEnumerableTests.cs
+++ b/Tests/Common/Util/MemoizingEnumerableTests.cs
@@ -1,4 +1,4 @@
-/*
+/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -50,5 +50,14 @@ public void EnumeratesOnce()
// enumerating memoized twice shouldn't matter
CollectionAssert.AreEqual(memoized.ToList(), memoized.ToList());
}
+
+ [Test]
+ public void GetsCount()
+ {
+ var list = new List {1, 2, 3, 4, 5};
+ var memoized = new MemoizingEnumerable(list);
+ Assert.AreEqual(5, memoized.Count);
+ Assert.AreEqual(memoized.Count, memoized.ToList().Count);
+ }
}
}
diff --git a/Tests/QuantConnect.Tests.csproj b/Tests/QuantConnect.Tests.csproj
index d82a2509df47..090688b5d399 100644
--- a/Tests/QuantConnect.Tests.csproj
+++ b/Tests/QuantConnect.Tests.csproj
@@ -31,7 +31,7 @@
-
+