Created
March 6, 2012 22:32
-
-
Save JeffJacobson/1989457 to your computer and use it in GitHub Desktop.
Defines extension methods that allows LINQ to be used with ArcObjects "IEnum..." types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using ESRI.ArcGIS.Carto; | |
using ESRI.ArcGIS.esriSystem; | |
using ESRI.ArcGIS.Geodatabase; | |
using ESRI.ArcGIS.Server; | |
namespace Wsdot.ArcObjects.Extensions | |
{ | |
public static class ArcObjectsLinqExtensions | |
{ | |
public static IEnumerable<long> AsEnumerable(this ILongArray longArray) | |
{ | |
for (int i = 0; i < longArray.Count; i++) | |
{ | |
yield return longArray.get_Element(i); | |
} | |
} | |
public static IEnumerable<IFeature> AsEnumerable(this IFeatureCursor source) | |
{ | |
Func<IFeature> next = () => source.NextFeature(); | |
IFeature current = next(); | |
while (current != null) | |
{ | |
yield return current; | |
current = next(); | |
} | |
} | |
public static IEnumerable<IMapLayerInfo> AsEnumerable(this IMapLayerInfos layerInfos) | |
{ | |
for (int i = 0; i < layerInfos.Count; i++) | |
{ | |
yield return layerInfos.get_Element(i); | |
} | |
} | |
public static IEnumerable<IServerObjectExtensionType> AsEnumerable(this IEnumServerObjectExtensionType source) | |
{ | |
Func<IServerObjectExtensionType> next = () => source.Next(); | |
IServerObjectExtensionType current = next(); | |
while (current != null) | |
{ | |
yield return current; | |
current = next(); | |
} | |
} | |
public static IEnumerable<IServerObjectConfiguration4> AsEnumerable(this IEnumServerObjectConfiguration source) | |
{ | |
Func<IServerObjectConfiguration4> next = () => source.Next() as IServerObjectConfiguration4; | |
var current = next(); | |
while (current != null) | |
{ | |
yield return current; | |
current = next(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on code from http://vernagus.blogspot.com/2008/07/using-linq-with-arcobjects.html