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

LINQ To Google Image and Google Groups

, 8 May 2007
A LINQ Implementation for Google Images/Groups Search
googlelinq.zip
Google
Google
bin
Release
Google.exe
Google.pdb
Google.csproj.user
Properties
expression-tree.JPG
google_linq_10.zip
Common
Google.csproj.user
Group
Image
using System;
using System.Collections.Generic;
using System.Text;

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

namespace MChen.Linq.Google
{
    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);
                    break;
                case ExpressionType.Call:
                    MethodCallExpression mce = expression as MethodCallExpression;
                    Console.WriteLine("{0}", mce.Method.Name);
                    foreach (Expression ex in mce.Arguments)
                        InternalDebugExpressionTree(ex, "Param", depth + 1);
                    break;
                case ExpressionType.Constant:
                    ConstantExpression ce = expression as ConstantExpression;
                    Console.WriteLine("{0} = {1}", ce.Value.GetType().Name, ce.Value );
                    break;
                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);
                    }
                    break;
                case ExpressionType.Parameter:
                    ParameterExpression pex = expression as ParameterExpression;
                    Console.WriteLine("Parameter Name = {0}", pex.Name);
                    break;
                case ExpressionType.MemberAccess:
                    MemberExpression mex = expression as MemberExpression;
                    Console.WriteLine("{0}", mex.Member.Name);
                    break;
                //arithmetic
                case ExpressionType.Add:
                case ExpressionType.AddChecked:
                case ExpressionType.Divide:
                case ExpressionType.Modulo:
                case ExpressionType.Multiply:
                case ExpressionType.MultiplyChecked:
                case ExpressionType.Subtract:
                case ExpressionType.SubtractChecked:
                //bitwise
                case ExpressionType.And:
                case ExpressionType.Or:
                case ExpressionType.ExclusiveOr:
                //shift
                case ExpressionType.LeftShift:
                case ExpressionType.RightShift:
                //conditional boolean
                case ExpressionType.AndAlso:
                case ExpressionType.OrElse:
                //comparison
                case ExpressionType.Equal:
                case ExpressionType.NotEqual:
                case ExpressionType.GreaterThan:
                case ExpressionType.GreaterThanOrEqual:
                case ExpressionType.LessThan:
                case ExpressionType.LessThanOrEqual:
                //coalesce
                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);
                    break;

                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:
                default:
                    Console.WriteLine("{0}", expression.NodeType);
                    break;
            }
            return;
        }
    }
}

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 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

Share

About the Author

Ming.Chen
Web Developer
United States United States

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