Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Roslyn CTP: Three Introductory Projects

, 8 May 2012
An introduction to the Roslyn CTP
RoslynCTPSamples.zip
CodeGenerator
bin
Debug
CodeGenerator.vshost.exe
CodeGenerator.vshost.exe.manifest
Release
CodeGenerator.csproj.user
obj
x86
Debug
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
EventImplementer
bin
Debug
Release
EventImplementer.csproj.user
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
source.extension.vsixmanifest
RoslynCTPLibrary
bin
Debug
RoslynCTPSamples.dll
RoslynCTPSamples.pdb
Release
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
RoslynCTPSamples.dll
RoslynCTPSamples.pdb
TempPE
Properties
CodeGeneratorTest
bin
Debug
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
RefactoringConsole
bin
Debug
RefactoringConsole.vshost.exe
RefactoringConsole.vshost.exe.manifest
obj
x86
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
RefactoringExtension
bin
Debug
Release
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
RefactoringExtension.csproj.user
source.extension.vsixmanifest
using System;
using System.Collections;
using System.Linq;

namespace CodeGenerator {
    public static class EnumerableExtensions {
        public static System.Collections.Generic.IEnumerable<TFiltered> Where<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.Where(source.OfType<TFiltered>(), predicate);
        }

        public static System.Collections.Generic.IEnumerable<TFiltered> Where<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int, bool> predicate) where TFiltered : TSource {
            return Enumerable.Where(source.OfType<TFiltered>(), predicate);
        }

        public static System.Collections.Generic.IEnumerable<TResult> Select<TSource, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TResult> selector) where TFiltered : TSource {
            return Enumerable.Select(source.OfType<TFiltered>(), selector);
        }

        public static System.Collections.Generic.IEnumerable<TResult> Select<TSource, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int, TResult> selector) where TFiltered : TSource {
            return Enumerable.Select(source.OfType<TFiltered>(), selector);
        }

        public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, System.Collections.Generic.IEnumerable<TResult>> selector) where TFiltered : TSource {
            return Enumerable.SelectMany(source.OfType<TFiltered>(), selector);
        }

        public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int, System.Collections.Generic.IEnumerable<TResult>> selector) where TFiltered : TSource {
            return Enumerable.SelectMany(source.OfType<TFiltered>(), selector);
        }

        public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource, TCollection, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int, System.Collections.Generic.IEnumerable<TCollection>> collectionSelector, System.Func<TFiltered, TCollection, TResult> resultSelector) where TFiltered : TSource {
            return Enumerable.SelectMany(source.OfType<TFiltered>(), collectionSelector, resultSelector);
        }

        public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource, TCollection, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, System.Collections.Generic.IEnumerable<TCollection>> collectionSelector, System.Func<TFiltered, TCollection, TResult> resultSelector) where TFiltered : TSource {
            return Enumerable.SelectMany(source.OfType<TFiltered>(), collectionSelector, resultSelector);
        }

        public static System.Collections.Generic.IEnumerable<TFiltered> TakeWhile<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.TakeWhile(source.OfType<TFiltered>(), predicate);
        }

        public static System.Collections.Generic.IEnumerable<TFiltered> TakeWhile<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int, bool> predicate) where TFiltered : TSource {
            return Enumerable.TakeWhile(source.OfType<TFiltered>(), predicate);
        }

        public static System.Collections.Generic.IEnumerable<TFiltered> SkipWhile<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.SkipWhile(source.OfType<TFiltered>(), predicate);
        }

        public static System.Collections.Generic.IEnumerable<TFiltered> SkipWhile<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int, bool> predicate) where TFiltered : TSource {
            return Enumerable.SkipWhile(source.OfType<TFiltered>(), predicate);
        }

        public static System.Linq.IOrderedEnumerable<TFiltered> OrderBy<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector) where TFiltered : TSource {
            return Enumerable.OrderBy(source.OfType<TFiltered>(), keySelector);
        }

        public static System.Linq.IOrderedEnumerable<TFiltered> OrderBy<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.OrderBy(source.OfType<TFiltered>(), keySelector, comparer);
        }

        public static System.Linq.IOrderedEnumerable<TFiltered> OrderByDescending<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector) where TFiltered : TSource {
            return Enumerable.OrderByDescending(source.OfType<TFiltered>(), keySelector);
        }

        public static System.Linq.IOrderedEnumerable<TFiltered> OrderByDescending<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.OrderByDescending(source.OfType<TFiltered>(), keySelector, comparer);
        }

        public static System.Collections.Generic.IEnumerable<System.Linq.IGrouping<TKey, TFiltered>> GroupBy<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector);
        }

        public static System.Collections.Generic.IEnumerable<System.Linq.IGrouping<TKey, TFiltered>> GroupBy<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector, comparer);
        }

        public static System.Collections.Generic.IEnumerable<System.Linq.IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector, elementSelector);
        }

        public static System.Collections.Generic.IEnumerable<System.Linq.IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector, elementSelector, comparer);
        }

        public static System.Collections.Generic.IEnumerable<TResult> GroupBy<TSource, TKey, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TKey, System.Collections.Generic.IEnumerable<TFiltered>, TResult> resultSelector) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector, resultSelector);
        }

        public static System.Collections.Generic.IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector, System.Func<TKey, System.Collections.Generic.IEnumerable<TElement>, TResult> resultSelector) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector, elementSelector, resultSelector);
        }

        public static System.Collections.Generic.IEnumerable<TResult> GroupBy<TSource, TKey, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TKey, System.Collections.Generic.IEnumerable<TFiltered>, TResult> resultSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector, resultSelector, comparer);
        }

        public static System.Collections.Generic.IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector, System.Func<TKey, System.Collections.Generic.IEnumerable<TElement>, TResult> resultSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.GroupBy(source.OfType<TFiltered>(), keySelector, elementSelector, resultSelector, comparer);
        }

        public static System.Collections.Generic.Dictionary<TKey, TFiltered> ToDictionary<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector) where TFiltered : TSource {
            return Enumerable.ToDictionary(source.OfType<TFiltered>(), keySelector);
        }

        public static System.Collections.Generic.Dictionary<TKey, TFiltered> ToDictionary<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.ToDictionary(source.OfType<TFiltered>(), keySelector, comparer);
        }

        public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector) where TFiltered : TSource {
            return Enumerable.ToDictionary(source.OfType<TFiltered>(), keySelector, elementSelector);
        }

        public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.ToDictionary(source.OfType<TFiltered>(), keySelector, elementSelector, comparer);
        }

        public static System.Linq.ILookup<TKey, TFiltered> ToLookup<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector) where TFiltered : TSource {
            return Enumerable.ToLookup(source.OfType<TFiltered>(), keySelector);
        }

        public static System.Linq.ILookup<TKey, TFiltered> ToLookup<TSource, TKey, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.ToLookup(source.OfType<TFiltered>(), keySelector, comparer);
        }

        public static System.Linq.ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector) where TFiltered : TSource {
            return Enumerable.ToLookup(source.OfType<TFiltered>(), keySelector, elementSelector);
        }

        public static System.Linq.ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TKey> keySelector, System.Func<TFiltered, TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) where TFiltered : TSource {
            return Enumerable.ToLookup(source.OfType<TFiltered>(), keySelector, elementSelector, comparer);
        }

        public static TFiltered First<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.First(source.OfType<TFiltered>(), predicate);
        }

        public static TFiltered FirstOrDefault<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.FirstOrDefault(source.OfType<TFiltered>(), predicate);
        }

        public static TFiltered Last<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.Last(source.OfType<TFiltered>(), predicate);
        }

        public static TFiltered LastOrDefault<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.LastOrDefault(source.OfType<TFiltered>(), predicate);
        }

        public static TFiltered Single<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.Single(source.OfType<TFiltered>(), predicate);
        }

        public static TFiltered SingleOrDefault<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.SingleOrDefault(source.OfType<TFiltered>(), predicate);
        }

        public static bool Any<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.Any(source.OfType<TFiltered>(), predicate);
        }

        public static bool All<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.All(source.OfType<TFiltered>(), predicate);
        }

        public static int Count<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.Count(source.OfType<TFiltered>(), predicate);
        }

        public static long LongCount<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, bool> predicate) where TFiltered : TSource {
            return Enumerable.LongCount(source.OfType<TFiltered>(), predicate);
        }

        public static TFiltered Aggregate<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TFiltered, TFiltered> func) where TFiltered : TSource {
            return Enumerable.Aggregate(source.OfType<TFiltered>(), func);
        }

        public static TAccumulate Aggregate<TSource, TAccumulate, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, TAccumulate seed, System.Func<TAccumulate, TFiltered, TAccumulate> func) where TFiltered : TSource {
            return Enumerable.Aggregate(source.OfType<TFiltered>(), seed, func);
        }

        public static TResult Aggregate<TSource, TAccumulate, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, TAccumulate seed, System.Func<TAccumulate, TFiltered, TAccumulate> func, System.Func<TAccumulate, TResult> resultSelector) where TFiltered : TSource {
            return Enumerable.Aggregate(source.OfType<TFiltered>(), seed, func, resultSelector);
        }

        public static int Sum<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int> selector) where TFiltered : TSource {
            return Enumerable.Sum(source.OfType<TFiltered>(), selector);
        }

        public static long Sum<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, long> selector) where TFiltered : TSource {
            return Enumerable.Sum(source.OfType<TFiltered>(), selector);
        }

        public static float Sum<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, float> selector) where TFiltered : TSource {
            return Enumerable.Sum(source.OfType<TFiltered>(), selector);
        }

        public static double Sum<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, double> selector) where TFiltered : TSource {
            return Enumerable.Sum(source.OfType<TFiltered>(), selector);
        }

        public static decimal Sum<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, decimal> selector) where TFiltered : TSource {
            return Enumerable.Sum(source.OfType<TFiltered>(), selector);
        }

        public static int Min<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int> selector) where TFiltered : TSource {
            return Enumerable.Min(source.OfType<TFiltered>(), selector);
        }

        public static long Min<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, long> selector) where TFiltered : TSource {
            return Enumerable.Min(source.OfType<TFiltered>(), selector);
        }

        public static float Min<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, float> selector) where TFiltered : TSource {
            return Enumerable.Min(source.OfType<TFiltered>(), selector);
        }

        public static double Min<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, double> selector) where TFiltered : TSource {
            return Enumerable.Min(source.OfType<TFiltered>(), selector);
        }

        public static decimal Min<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, decimal> selector) where TFiltered : TSource {
            return Enumerable.Min(source.OfType<TFiltered>(), selector);
        }

        public static TResult Min<TSource, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TResult> selector) where TFiltered : TSource {
            return Enumerable.Min(source.OfType<TFiltered>(), selector);
        }

        public static int Max<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int> selector) where TFiltered : TSource {
            return Enumerable.Max(source.OfType<TFiltered>(), selector);
        }

        public static long Max<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, long> selector) where TFiltered : TSource {
            return Enumerable.Max(source.OfType<TFiltered>(), selector);
        }

        public static float Max<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, float> selector) where TFiltered : TSource {
            return Enumerable.Max(source.OfType<TFiltered>(), selector);
        }

        public static double Max<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, double> selector) where TFiltered : TSource {
            return Enumerable.Max(source.OfType<TFiltered>(), selector);
        }

        public static decimal Max<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, decimal> selector) where TFiltered : TSource {
            return Enumerable.Max(source.OfType<TFiltered>(), selector);
        }

        public static TResult Max<TSource, TResult, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, TResult> selector) where TFiltered : TSource {
            return Enumerable.Max(source.OfType<TFiltered>(), selector);
        }

        public static double Average<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, int> selector) where TFiltered : TSource {
            return Enumerable.Average(source.OfType<TFiltered>(), selector);
        }

        public static double Average<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, long> selector) where TFiltered : TSource {
            return Enumerable.Average(source.OfType<TFiltered>(), selector);
        }

        public static float Average<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, float> selector) where TFiltered : TSource {
            return Enumerable.Average(source.OfType<TFiltered>(), selector);
        }

        public static double Average<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, double> selector) where TFiltered : TSource {
            return Enumerable.Average(source.OfType<TFiltered>(), selector);
        }

        public static decimal Average<TSource, TFiltered>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TFiltered, decimal> selector) where TFiltered : TSource {
            return Enumerable.Average(source.OfType<TFiltered>(), selector);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Whaeth

Hungary Hungary
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 8 May 2012
Article Copyright 2011 by Whaeth
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid