public static IEnumerable <IFeature> GetFeatures(this ISelectionSet set, IQueryFilter filter = null, enumRecyclingPolicy policy = enumRecyclingPolicy.DoNotRecycle) { ICursor cursor; set.Search(filter, enumRecyclingPolicy.Recycle == policy, out cursor); var featureCursor = (IFeatureCursor)cursor; IFeature feature; while (null != (feature = featureCursor.NextFeature())) { yield return(feature); } if (Marshal.IsComObject(cursor)) { Marshal.ReleaseComObject(cursor); } }
public static IEnumerable <IFeature> GetFeatures(this IFeatureClass featureClass, IQueryFilter queryFilter = null, enumRecyclingPolicy policy = enumRecyclingPolicy.DoNotRecycle) { IFeatureCursor featureCursor = featureClass.Search(queryFilter, enumRecyclingPolicy.Recycle == policy); IFeature feature; while (null != (feature = featureCursor.NextFeature())) { yield return(feature); } if (Marshal.IsComObject(featureCursor)) { Marshal.ReleaseComObject(featureCursor); } }