// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // using System; using System.Collections; using System.Collections.Generic; using Microsoft.SqlServer.Management.Smo; namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel { /// /// Wrapper to convert non-generic Smo enumerables to generic enumerable types for easier use in /// /// public class SmoCollectionWrapper : IEnumerable where T : SqlSmoObject { private SmoCollectionBase collection; /// /// Constructor which accepts a containing the objects /// to wrap /// /// or null if none were set public SmoCollectionWrapper(SmoCollectionBase collection) { this.collection = collection; } /// /// /// /// public IEnumerator GetEnumerator() { if (collection == null) { yield break; } foreach(Object obj in collection) { yield return (T)obj; } } /// /// /// /// IEnumerator IEnumerable.GetEnumerator() { return collection?.GetEnumerator(); } } }