Cast Valid IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Cast Valid IEnumerable

Demo Code

// Permission is hereby granted, free of charge, to any person
using System.Globalization;
using System.Linq;
using System.Collections;
using System.Text;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System;//from w  ww. ja v  a  2 s. co m

public class Main{
    public static IEnumerable<T> CastValid<T>(this IEnumerable enumerable)
    {
      ValidationUtils.ArgumentNotNull(enumerable, "enumerable");

      return enumerable.Cast<object>().Where(o => o is T).Cast<T>();
    }
}

Related Tutorials