Created
          August 30, 2012 02:14 
        
      - 
      
- 
        Save ritalin/3521721 to your computer and use it in GitHub Desktop. 
    Any filter extension
  
        
  
    
      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 System.Linq; | |
| namespace Sample { | |
| public static class EnumerableAnyExtensions { | |
| public static IEnumerable<TSource> WhereAny<TSource>(this IEnumerable<TSource> inSelf, params Func<TSource, bool>[] inFilters) { | |
| return inSelf.Where( | |
| source => inFilters.Any(fn => fn(source)) | |
| ); | |
| } | |
| public static int CountAny<TSource>(this IEnumerable<TSource> inSelf, params Func<TSource, bool>[] inFilters) { | |
| return inSelf.Count( | |
| source => inFilters.Any(fn => fn(source)) | |
| ); | |
| } | |
| } | |
| } | 
  
    
      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 System.Linq; | |
| using NUnit.Framework; | |
| namespace Sample { | |
| [TestFixture] | |
| public class EnumerableTest { | |
| [Test] | |
| public void _2か3どちらかの倍数() { | |
| var count = Enumerable.Range(1, 10) | |
| .CountAny( | |
| i => i % 2 == 0, | |
| i => i % 3 == 0 | |
| ); | |
| Assert.That(count, Is.EqualTo(7)); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment