// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net) // All rights reserved. // // This file is part of Regionerate. // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, // or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System.Collections; using System.Collections.Generic; using Rauchy.Regionerate.Domain.Entities; namespace Rauchy.Regionerate.Shared.Components { public static class CodeFilter { #region Methods (1) public static IEnumerable Only( IList codeCollection ) where T : Code { return new OnlyFilter( codeCollection ); } #endregion #region Nested Classes (1) private class OnlyFilter : IEnumerable where T : Code { private readonly IList _codeCollection; public OnlyFilter( IList codeCollection ) { _codeCollection = codeCollection; } public IEnumerator GetEnumerator() { foreach ( Code code in _codeCollection ) { T t = code as T; if ( t != null ) { yield return t; } } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } #endregion } }