示例#1
0
        /// <summary>
        ///     Creates an <see cref="IEnumerable{T}" /> from an <see cref="IEnumWorkspaceEx" />
        /// </summary>
        /// <param name="source">An <see cref="IEnumWorkspaceEx" /> to create an <see cref="IEnumerable{T}" /> from.</param>
        /// <returns>An <see cref="IEnumerable{T}" /> that contains the feature classes from the input source.</returns>
        public static IEnumerable <IWorkspace> AsEnumerable(this IEnumWorkspaceEx source)
        {
            if (source != null)
            {
                source.Reset();
                IWorkspace workspace = source.Next();
                while (workspace != null)
                {
                    yield return(workspace);

                    workspace = source.Next();
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Gets the workspace that satisifies the <paramref name="predicate" /> criteria.
        ///     map.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="predicate">A function to test each element for a condition.</param>
        /// <returns>
        ///     Returns a <see cref="IWorkspace" /> representing the workspace in the map that is being edited.
        /// </returns>
        /// <exception cref="ArgumentNullException">predicate</exception>
        public static IWorkspace GetWorkspace(this IMap source, Predicate <IWorkspace> predicate)
        {
            if (source == null)
            {
                return(null);
            }
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            IMMWorkspaceManagerMap manager    = new MMWorkspaceManagerClass();
            IEnumWorkspaceEx       workspaces = manager.GetMapWorkspaces(source);

            return(workspaces.AsEnumerable().FirstOrDefault(workspace => predicate(workspace)));
        }