Click here to Skip to main content
13,301,664 members (62,992 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads


47 bookmarked
Posted 1 May 2007

LINQ To Google Image and Google Groups

, 8 May 2007
A LINQ Implementation for Google Images/Groups Search
using System;
using System.Collections.Generic;
using System.Text;

using System.Linq;
using System.Linq.Expressions;

namespace MChen.Linq.GoogleSearch.Common
    /// <summary>
    /// Diagnostic class for debug purposes
    /// </summary>
    internal class Diagnostic
        public static void DebugExpressionTree(Expression expression)
            InternalDebugExpressionTree(expression, "Top", 0);

        private static string Indent(int num)
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < num; ++i) sb.Append("   ");
            return sb.ToString();

        private static void InternalDebugExpressionTree(Expression expression, string type, int depth)
            Console.Write("{0}{1} is {2}:  ", Indent(depth), type, expression.GetType().Name);
            switch (expression.NodeType)
                case ExpressionType.ArrayLength:
                case ExpressionType.Convert:
                case ExpressionType.ConvertChecked:
                case ExpressionType.Negate:
                case ExpressionType.NegateChecked:
                case ExpressionType.Not:
                case ExpressionType.TypeAs:
                case ExpressionType.Quote:
                    UnaryExpression ue = expression as UnaryExpression;
                    Console.WriteLine("{0}", ue.NodeType);
                    InternalDebugExpressionTree(ue.Operand, "Operand", depth + 1);
                case ExpressionType.Call:
                    MethodCallExpression mce = expression as MethodCallExpression;
                    Console.WriteLine("{0}", mce.Method.Name);
                    if (mce.Object != null)
                        InternalDebugExpressionTree(mce.Object, "Object", depth + 1);
                    foreach (Expression ex in mce.Arguments)
                        InternalDebugExpressionTree(ex, "Param", depth + 1);
                case ExpressionType.Constant:
                    ConstantExpression ce = expression as ConstantExpression;
                    Console.WriteLine("{0} = {1}", ce.Value.GetType().Name, ce.Value );
                case ExpressionType.Lambda:
                    LambdaExpression lex = expression as LambdaExpression;
                    Console.WriteLine("{0}", expression.NodeType);
                    InternalDebugExpressionTree(lex.Body, "Body", depth + 1);
                    foreach (Expression exp in lex.Parameters)
                        InternalDebugExpressionTree(exp, "Param", depth + 1);
                case ExpressionType.Parameter:
                    ParameterExpression pex = expression as ParameterExpression;
                    Console.WriteLine("Parameter Name = {0}", pex.Name);
                case ExpressionType.MemberAccess:
                    MemberExpression mex = expression as MemberExpression;
                    Console.WriteLine("{0}", mex.Member.Name);
                case ExpressionType.Add:
                case ExpressionType.AddChecked:
                case ExpressionType.Divide:
                case ExpressionType.Modulo:
                case ExpressionType.Multiply:
                case ExpressionType.MultiplyChecked:
                case ExpressionType.Subtract:
                case ExpressionType.SubtractChecked:
                case ExpressionType.And:
                case ExpressionType.Or:
                case ExpressionType.ExclusiveOr:
                case ExpressionType.LeftShift:
                case ExpressionType.RightShift:
                //conditional boolean
                case ExpressionType.AndAlso:
                case ExpressionType.OrElse:
                case ExpressionType.Equal:
                case ExpressionType.NotEqual:
                case ExpressionType.GreaterThan:
                case ExpressionType.GreaterThanOrEqual:
                case ExpressionType.LessThan:
                case ExpressionType.LessThanOrEqual:
                case ExpressionType.Coalesce:
                //array index
                case ExpressionType.ArrayIndex:
                    BinaryExpression bex = expression as BinaryExpression;
                    Console.WriteLine("{0}", bex.NodeType);
                    InternalDebugExpressionTree(bex.Left, "Left", depth + 1);
                    InternalDebugExpressionTree(bex.Right, "Right", depth + 1);

                case ExpressionType.Conditional:
                case ExpressionType.Funclet:
                case ExpressionType.Invoke:
                case ExpressionType.ListInit:
                case ExpressionType.MemberInit:
                case ExpressionType.New:
                case ExpressionType.NewArrayBounds:
                case ExpressionType.NewArrayInit:
                case ExpressionType.TypeIs:
                    Console.WriteLine("{0}", expression.NodeType);
            if (depth == 0)

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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 8 May 2007
Article Copyright 2007 by Ming.Chen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid