+2008-05-20 Roei Erez <roeie@mainsoft.com>
+
+ * Extensions.cs: Add 'IsGenericImplementationOf' extension method
+
2008-05-15 Jb Evain <jbevain@novell.com>
* UnaryExpression.cs, EmitContext.cs: emit convert from and
return self.GetGenericTypeDefinition () == type;
}
+ public static bool IsGenericImplementationOf (this Type self, Type type)
+ {
+ foreach (Type iface in self.GetInterfaces ())
+ if (iface.IsGenericInstanceOf (type))
+ return true;
+ return false;
+ }
+
public static bool IsAssignableTo (this Type self, Type type)
{
return type.IsAssignableFrom (self) ||
+2008-05-20 Roei Erez <roeie@mainsoft.com>
+
+ * Queryable.cs: Implement the non-generic AsQureyable method.
+
2008-05-20 Marek Safar <marek.safar@gmail.com>
* Enumerable.cs: Removed GroupBy MonoTODO.
public static IQueryable<TElement> AsQueryable<TElement> (this IEnumerable<TElement> source)
{
+ if (source == null)
+ throw new ArgumentNullException ("source");
+
var queryable = source as IQueryable<TElement>;
if (queryable != null)
return queryable;
[MonoTODO]
public static IQueryable AsQueryable (this IEnumerable source)
{
+ if (source == null)
+ throw new ArgumentNullException ("source");
+
var queryable = source as IQueryable;
if (queryable != null)
return queryable;
- throw new NotImplementedException ();
+ Type sourceType = source.GetType ();
+ if (!sourceType.IsGenericImplementationOf (typeof (IEnumerable<>)))
+ throw new ArgumentException ("source is not IEnumerable<>");
+
+ Type sourceArgType = sourceType.GetFirstGenericArgument ();
+ return (IQueryable) Activator.CreateInstance (typeof (QueryableEnumerable<>)
+ .MakeGenericType (sourceArgType), source);
}
#endregion
+2008-05-20 Roei Erez <roeie@mainsoft.com>
+
+ * Add tests for Queryable.AsQureyable
+
2008-05-15 Roei Erez <roeie@mainsoft.com>
* EnumerableAsQueryableTest.cs: test cases for Queryable.AsQueryable() implementation.
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Reflection;
+using System.Collections;
namespace MonoTests.System.Linq {
Expression e = Expression.Call (method, _src.Expression, Expression.Constant(0));
_src.Provider.Execute (e);
}
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void NullEnumerable ()
+ {
+ IEnumerable<int> a = null;
+ a.AsQueryable ();
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void NonGenericEnumerable1 ()
+ {
+ new MyEnum ().AsQueryable ();
+ }
+
+ [Test]
+ public void NonGenericEnumerable2 ()
+ {
+ IEnumerable<int> nonGen = new int[] { 1, 2, 3 };
+ Assert.IsTrue (nonGen.AsQueryable () is IQueryable<int>);
+ }
+ }
+
+ class MyEnum : IEnumerable
+ {
+ public IEnumerator GetEnumerator ()
+ {
+ throw new NotImplementedException ();
+ }
}
class CustomEqualityComparer : IEqualityComparer<int> {