Show / Hide Table of Contents

Struct ListCastEnumerator<TBase, TItem>

A custom enumerator that iterates over a List and casts its objects to the given type.

All objects must be of the specified type, or the iterator will not function.

Implements
IEnumerator<TItem>
IEnumerator
IDisposable
IEnumerable<TItem>
IEnumerable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
public struct ListCastEnumerator<TBase, TItem> : IEnumerator<TItem>, IEnumerator, IDisposable, IEnumerable<TItem>, IEnumerable where TItem : TBase
Type Parameters
Name Description
TBase

Type items in the list are stored as.

TItem

Actual type of items in the list.

Remarks

This type is a struct, and as such is much more efficient when used in a foreach loop than a function returning IEnumerable<T> or using System.LINQ extensions such as Where.

Otherwise, it has basically the same characteristics that exposing a list as IEnumerable<T> would; so if you need to expose items as some type like IEnumerable, and the items are internally stored as a list, this can be a good option. This type does implement IEnumerable, and as such can be used directly with functions that require one (for example, System.LINQ). However, this will have reduced performance due to boxing of the iterator.

Constructors

View Source

ListCastEnumerator(List<TBase>)

Constructor.

Declaration
public ListCastEnumerator(List<TBase> list)
Parameters
Type Name Description
List<TBase> list

List to iterate over.

Properties

View Source

Current

Declaration
public TItem Current { get; }
Property Value
Type Description
TItem

Methods

View Source

Dispose()

Declaration
public void Dispose()
View Source

GetEnumerator()

Returns this enumerator.

Declaration
public ListCastEnumerator<TBase, TItem> GetEnumerator()
Returns
Type Description
ListCastEnumerator<TBase, TItem>

This enumerator.

View Source

MoveNext()

Declaration
public bool MoveNext()
Returns
Type Description
bool

Implements

IEnumerator<T>
IEnumerator
IDisposable
IEnumerable<T>
IEnumerable

Extension Methods

Utility.Yield<T>(T)
  • View Source
In this article
Back to top Generated by DocFX