This project has moved. For the latest updates, please go here.

Expression Demo

This demo creates two expression that are used to
  1. filter a list of type to include only types that are either abstract or not class and have more than 50 members
  2. create string from a type that shows the type's fullname and base type's fullname

using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;

using NQuery;

namespace NQueryQuickDemo2
    class Program
        static void Main(string[] args)
            // Get a lists with all types
            Console.WriteLine("Loading types...");
            List<Type> typeList = new List<Type>();
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())

            // Create an empty data context
            DataContext dataContext = new DataContext();
            // Create expression to filter types
            Expression filterExpr = new Expression("(@Type.IsAbstract OR NOT @Type.IsClass) AND @Type.GetMembers().Length > 50", dataContext);
            filterExpr.Parameters.Add("@Type", typeof(Type));

			// Create expression to create a value from a type
            Expression valueExpr = new Expression("@Type.FullName + COALESCE(' : ' + @Type.BaseType.FullName, '')", dataContext);
            valueExpr.Parameters.Add("@Type", typeof(Type));

            foreach (Type type in typeList)
                filterExpr.Parameters["@Type"].Value = type;
                valueExpr.Parameters["@Type"].Value = type;

                bool filterResult = Convert.ToBoolean(filterExpr.Evaluate());
                string valueResult = Convert.ToString(valueExpr.Evaluate());

                if (filterResult)

Last edited Aug 26, 2006 at 4:28 PM by terrajobst, version 1


No comments yet.