public static void EnsureCountEquals <T>( this IEnumerable <T> collection, int count, string checkedVariableName, [CallerMemberName] string callerMethod = "") { if (string.IsNullOrEmpty(callerMethod)) { callerMethod = "Unknown"; } // Get the collection count var collectionCount = -1; collectionCount = SeeingSharpUtil.GetCollectionCount(collection); // Check result if (collectionCount != count) { throw new SeeingSharpCheckException(string.Format( "Collection {0} within method {1} does not have the expected count of elements (expected {2})!", checkedVariableName, callerMethod, count, collectionCount)); } }
public static void EnsureCountInRange <T>( this IEnumerable <T> collection, int countMin, int countMax, string checkedVariableName, [CallerMemberName] string callerMethod = "") { if (string.IsNullOrEmpty(callerMethod)) { callerMethod = "Unknown"; } // Get the collection count var collectionCount = -1; collectionCount = SeeingSharpUtil.GetCollectionCount(collection); // Check result if (collectionCount < countMin || collectionCount > countMax) { throw new SeeingSharpCheckException( $"Collection {checkedVariableName} within method {callerMethod} does not have the expected count of elements (expected min {countMin} to max {countMax}, current count is {collectionCount})!"); } }