ICursorExtensions Class

This class contains extension methods that convert ICursor into IEnumerable<IRow> and IFeatureCursor into IEnumerable<IFeature>.


Methods

NameDescription
ICursor.AsEnumerable()Release the cursor explicitly to avoid leaking database resources.
ICursor.AsEnumerable(Boolean)Delete the existing Feature in the database corresponding to the current position of the cursor.
ICursor.ToDisposable()Converts the ArcObjects COM [ICursor] to DisposableCursor.
IFeatureCursor.AsEnumerable()Converts the ArcObjects COM IFeatureCursor to a .NET enumerable object.
IFeatureCursor.AsEnumerable(Boolean)Converts the ArcObjects COM IFeatureCursor to a .NET enumerable object.
IFeatureCursor.ToDisposable()Converts the ArcObjects COM IFeatureCursor to DisposableFeatureCursor.

ICursor.AsEnumerable() Method

Converts the ArcObjects COM cursor to a .NET enumerable object.

Use dark colors for code blocksCopy
1
public static IEnumerable<IRow> AsEnumerable(this ICursor source)

The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must obtain another instance of the ICursor and call its AsEnumberable() method.

ICursor.AsEnumerable(Boolean) Method

Converts the ArcObjects COM cursor to a .NET enumerable object. The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. After it's iterated via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., To reuse the enumerator, you must obtain another instance of the Cursor and call its AsEnumberable() method. The Cursor will be automatically released after the iteration when releaseAfterUse is true.

Use dark colors for code blocksCopy
1
public static IEnumerable<IRow> AsEnumerable(this ICursor source, bool releaseAfterUse)
Parameter nameDescription
releaseAfterUseSpecifies whether to release the COM cursor after use. Releasing the COM cursor avoids leaking database resources.

Usage:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
    ICursor rowCursor = table.Search(null, false);
    IEnumerable<IRow> rows = rowCursor.AsEnumerable(true);
    //Since releaseAfterUse is true, there is no need to explictly release the COM cursor after the iteration.
    foreach (IRow r in rows)
    {
        // perform your operation
    }

ICursor.ToDisposable() Method

Converts the ArcObjects COM [ICursor] to DisposableCursor. This method returns a DisposableCursor object.

IFeatureCursor.AsEnumerable() Method

Converts the ArcObjects COM IFeatureCursor to a .NET enumerable object.

Use dark colors for code blocksCopy
1
public static IEnumerable<IFeature> AsEnumerable(this IFeatureCursor source)

The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must obtain another instance of the FeatureCursor and call its AsEnumberable() method.

IFeatureCursor.AsEnumerable(Boolean) Method

Converts the ArcObjects COM IFeatureCursor to a .NET enumerable object. The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must obtain another instance of the FeatureCursor and call its AsEnumberable() method. The FeatureCursor will be automatically released after the iteration when releaseAfterUse is true.

Use dark colors for code blocksCopy
1
public static IEnumerable<IFeature> AsEnumerable(this IFeatureCursor source, bool releaseAfterUse)
Parameter nameDescription
releaseAfterUseSpecifies whether to release the COM cursor after use. Releasing the COM cursor avoids leaking database resources.

Usage:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
    IFeatureCursor featureCursor = featureClass.Search(null, false);
    IEnumerable<IFeature> features = featureCursor.AsEnumerable(true);
    //Since releaseAfterUse is true, there is no need to explictly release the COM cursor after the iteration.
    foreach (IFeature f in features)
    {
        // perform your operation
    }

IFeatureCursor.ToDisposable() Method

Converts the ArcObjects COM IFeatureCursor to DisposableFeatureCursor. This method returns a DisposableFeatureCursor object.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.