Files
DP44/Common/DTS.Common.Utilities/LargeArray.Enumerator.cs

174 lines
6.4 KiB
C#
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
/*
* LargeArray.Enumerator.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Text;
using DTS.Common.Utilities;
using DTS.Common.Utilities.DotNetProgrammingConstructs;
namespace DTS.Common.Utilities.IO.MemoryMap
{
// *** see LargeArray.cs ***
public partial class LargeArray<T>
{
/// <summary>
/// An enumerator class for <see cref="T:LargeArray"/>.
/// </summary>
public class Enumerator : Exceptional, IEnumerator
{
/// <summary>
/// Initialize an instance of the <see cref="T:LargeArray.Enumerator"/> class.
/// </summary>
///
/// <param name="enumeratee">
/// The <see cref="T:LargeArray"/> object to be operated upon by this instance.
/// </param>
///
public Enumerator(LargeArray<T> enumeratee)
{
try
{
Enumeratee = enumeratee;
CurrentIndex = (Enumeratee.LargeCount > 0 ? (ulong?)0 : null);
}
catch (System.Exception ex)
{
throw new Exception("encountered problem ", ex);
}
}
/// <summary>
/// Get the <see cref="T:LargeArray"/> that his enumerator object is
/// acting upon.
/// </summary>
protected LargeArray<T> Enumeratee
{
get => _Enumeratee.Value;
private set => _Enumeratee.Value = value;
}
private Property<LargeArray<T>> _Enumeratee
= new Property<LargeArray<T>>(
typeof(Enumerator).FullName + ".Enumeratee",
null,
false
);
/// <summary>
/// The <see cref="ulong"/> index of the current item.
/// </summary>
private ulong? CurrentIndex
{
get;
set;
}
#region IEnumerator interface
// *********************************************************************
// ******************** BEGIN IEnumerator Interface ********************
// *********************************************************************
/// <summary>
/// Get the current element in the collection.
/// </summary>
///
/// <exception cref="System.InvalidOperationException">
/// The enumerator is positioned before the first element of the collection or after the last element OR...
/// The collection was modified after the enumerator was created.
/// </exception>
///
public object Current
{
get
{
try
{
if (null == CurrentIndex)
throw new InvalidOperationException("the current position is outside of the collection");
else if ( /*EnumerateeHasBeenModified*/ true)
throw new InvalidOperationException("the collection has been modified since this enumerator was created");
//else return Enumeratee[ (ulong) CurrentIndex ]; - inaccessible code - 6/9/2010 - dtm
}
catch (InvalidOperationException)
{
throw;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem getting current element in the collection", ex);
}
}
}
/// <summary>
/// Advances the enumerator to the next element of the collection.
/// </summary>
///
/// <returns>
/// <see cref="bool"/> true if the enumerator was successfully advanced to the next
/// element; false if the enumerator has passed the end of the collection.
/// </returns>
///
/// <exception cref="System.InvalidOperationException">
/// The collection was modified after the enumerator was created.
/// </exception>
///
public bool MoveNext()
{
//try
//{
throw new NotSupportedException("MemoryMapArray MoveNext not supported");
//}
//catch (InvalidOperationException ex) { throw ex; }
//catch (System.Exception ex)
//{
// throw new Exception("encountered problem advancing to the next element of the collection", ex);
//}
}
/// <summary>
/// Sets the enumerator to its initial position, which is before the first element
/// in the collection.
/// </summary>
///
/// <exception cref="System.InvalidOperationException">
/// The collection was modified after the enumerator was created.
/// </exception>
///
public void Reset()
{
//try
//{
// // TODO: implement
throw new NotSupportedException("MemoryMap.LargeArray Reset not supported");
//}
//catch (InvalidOperationException) { throw; }
//catch (System.Exception ex)
//{
// throw new Exception("encountered problem setting the enumerator to its initial position", ex);
//}
}
// *******************************************************************
// ******************** END IEnumerator Interface ********************
// *******************************************************************
#endregion
}
}
}