Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose QueryObject to VS Debugger so that its now possible to debug l…
…inq queries outside of the MongoDB-CSharp project.
  • Loading branch information
lanwin committed Sep 30, 2010
1 parent 2ea1bc0 commit e1305e6
Showing 1 changed file with 76 additions and 63 deletions.
139 changes: 76 additions & 63 deletions source/MongoDB/Linq/MongoQuery.cs
@@ -1,46 +1,53 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;

namespace MongoDB.Linq
{
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
///<summary>
///</summary>
///<typeparam name = "T"></typeparam>
internal class MongoQuery<T> : IOrderedQueryable<T>, IMongoQueryable
{
private readonly Expression _expression;
private readonly MongoQueryProvider _provider;

/// <summary>
/// Gets the expression tree that is associated with the instance of <see cref="T:System.Linq.IQueryable"/>.
/// Initializes a new instance of the <see cref = "MongoQuery&lt;T&gt;" /> class.
/// </summary>
/// <value></value>
/// <returns>
/// The <see cref="T:System.Linq.Expressions.Expression"/> that is associated with this instance of <see cref="T:System.Linq.IQueryable"/>.
/// </returns>
Expression IQueryable.Expression
/// <param name = "provider">The provider.</param>
public MongoQuery(MongoQueryProvider provider)
{
get { return _expression; }
if(provider == null)
throw new ArgumentNullException("provider");

_expression = Expression.Constant(this);
_provider = provider;
}

/// <summary>
/// Gets the type of the element(s) that are returned when the expression tree associated with this instance of <see cref="T:System.Linq.IQueryable"/> is executed.
/// Initializes a new instance of the <see cref = "MongoQuery&lt;T&gt;" /> class.
/// </summary>
/// <value></value>
/// <returns>
/// A <see cref="T:System.Type"/> that represents the type of the element(s) that are returned when the expression tree associated with this object is executed.
/// </returns>
Type IQueryable.ElementType
/// <param name = "provider">The provider.</param>
/// <param name = "expression">The expression.</param>
public MongoQuery(MongoQueryProvider provider, Expression expression)
{
get { return typeof(T); }
if(provider == null)
throw new ArgumentNullException("provider");
if(expression == null)
throw new ArgumentNullException("expression");

if(!typeof(IQueryable<T>).IsAssignableFrom(expression.Type))
throw new ArgumentOutOfRangeException("expression");
_provider = provider;
_expression = expression;
}

/// <summary>
/// Gets the name of the collection.
/// Gets the name of the collection.
/// </summary>
/// <value>The name of the collection.</value>
string IMongoQueryable.CollectionName
Expand All @@ -58,85 +65,91 @@ IMongoDatabase IMongoQueryable.Database
}

/// <summary>
/// Gets the query provider that is associated with this data source.
/// Gets the query object.
/// </summary>
/// <value></value>
/// <returns>
/// The <see cref="T:System.Linq.IQueryProvider"/> that is associated with this data source.
/// </returns>
IQueryProvider IQueryable.Provider
/// <returns></returns>
MongoQueryObject IMongoQueryable.GetQueryObject()
{
get { return this._provider; }
return QueryObject;
}

/// <summary>
/// Initializes a new instance of the <see cref="MongoQuery&lt;T&gt;"/> class.
/// Get the QueryObject for VS DebugView
/// </summary>
/// <param name="provider">The provider.</param>
public MongoQuery(MongoQueryProvider provider)
/// <value>The query.</value>
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
protected MongoQueryObject QueryObject
{
if (provider == null)
throw new ArgumentNullException("provider");

this._expression = Expression.Constant(this);
this._provider = provider;
get { return _provider.GetQueryObject(_expression); }
}

/// <summary>
/// Initializes a new instance of the <see cref="MongoQuery&lt;T&gt;"/> class.
/// Gets the expression tree that is associated with the instance of <see cref = "T:System.Linq.IQueryable" />.
/// </summary>
/// <param name="provider">The provider.</param>
/// <param name="expression">The expression.</param>
public MongoQuery(MongoQueryProvider provider, Expression expression)
/// <value></value>
/// <returns>
/// The <see cref = "T:System.Linq.Expressions.Expression" /> that is associated with this instance of <see cref = "T:System.Linq.IQueryable" />.
/// </returns>
Expression IQueryable.Expression
{
if (provider == null)
throw new ArgumentNullException("provider");
if (expression == null)
throw new ArgumentNullException("expression");
get { return _expression; }
}

if (!typeof(IQueryable<T>).IsAssignableFrom(expression.Type))
throw new ArgumentOutOfRangeException("expression");
this._provider = provider;
this._expression = expression;
/// <summary>
/// Gets the type of the element(s) that are returned when the expression tree associated with this instance of <see cref = "T:System.Linq.IQueryable" /> is executed.
/// </summary>
/// <value></value>
/// <returns>
/// A <see cref = "T:System.Type" /> that represents the type of the element(s) that are returned when the expression tree associated with this object is executed.
/// </returns>
Type IQueryable.ElementType
{
get { return typeof(T); }
}

/// <summary>
/// Returns an enumerator that iterates through the collection.
/// Gets the query provider that is associated with this data source.
/// </summary>
/// <value></value>
/// <returns>
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
/// The <see cref = "T:System.Linq.IQueryProvider" /> that is associated with this data source.
/// </returns>
public IEnumerator<T> GetEnumerator() {
return ((IEnumerable<T>)this._provider.Execute(_expression)).GetEnumerator();
IQueryProvider IQueryable.Provider
{
get { return _provider; }
}

/// <summary>
/// Returns an enumerator that iterates through a collection.
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
/// A <see cref = "T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection.
/// </returns>
IEnumerator IEnumerable.GetEnumerator() {
return ((IEnumerable)this._provider.Execute(_expression)).GetEnumerator();
public IEnumerator<T> GetEnumerator()
{
return ( (IEnumerable<T>)_provider.Execute(_expression) ).GetEnumerator();
}

/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// An <see cref = "T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
/// </returns>
public override string ToString() {
return _provider.GetQueryObject(_expression).ToString();
IEnumerator IEnumerable.GetEnumerator()
{
return ( (IEnumerable)_provider.Execute(_expression) ).GetEnumerator();
}

/// <summary>
/// Gets the query object.
/// Returns a <see cref = "System.String" /> that represents this instance.
/// </summary>
/// <returns></returns>
MongoQueryObject IMongoQueryable.GetQueryObject()
/// <returns>
/// A <see cref = "System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
return _provider.GetQueryObject(_expression);
return QueryObject.ToString();
}
}
}
}

0 comments on commit e1305e6

Please sign in to comment.