static void Main(string[] args) { List <string> strings = new List <string> { "Hello", "World!" }; Console.WriteLine("strings.GetType().Name: {0}", strings.GetType().Name); Console.WriteLine("strings is IEnumerable<string>: {0}", strings is IEnumerable <string>); Console.WriteLine("strings.GetType() == typeof(IEnumerable<string>): {0}", strings.GetType() == typeof(IEnumerable <string>)); TypeBinaryExpression typeIsExpression = Expression.TypeIs( Expression.Constant("Hello"), typeof(IEnumerable <char>)); TypeBinaryExpression typeEqualExpression = Expression.TypeEqual( Expression.Constant("Hello"), typeof(IEnumerable <char>)); Console.WriteLine("\n\n"); Console.WriteLine("typeIsExpression ({0}) value: {1}", typeIsExpression.ToString(), Expression.Lambda <Func <bool> >(typeIsExpression).Compile()()); Console.WriteLine("typeEqualExpression {0} value: {1}", typeEqualExpression.ToString(), Expression.Lambda <Func <bool> >(typeEqualExpression).Compile()()); Console.ReadKey(); }
// // Summary: // Visits the children of the System.Linq.Expressions.TypeBinaryExpression. // // Parameters: // node: // The expression to visit. // // Returns: // The modified expression, if it or any subexpression was modified; otherwise, // returns the original expression. protected override Expression VisitTypeBinary(TypeBinaryExpression node) { Console.WriteLine("VisitTypeBinary:"); Console.WriteLine('\t' + node.GetType().ToString()); Console.WriteLine('\t' + node.ToString()); return(base.VisitTypeBinary(node)); }
public void String() { TypeBinaryExpression expr = Expression.TypeIs(Expression.Constant(1), typeof(string)); Assert.AreEqual(ExpressionType.TypeIs, expr.NodeType, "TypeIs#04"); Assert.AreEqual(typeof(bool), expr.Type, "TypeIs#05"); Assert.AreEqual("(1 Is String)", expr.ToString(), "TypeIs#06"); }
public void Numeric() { TypeBinaryExpression expr = Expression.TypeIs(Expression.Constant(1), typeof(int)); Assert.AreEqual(ExpressionType.TypeIs, expr.NodeType, "TypeIs#01"); Assert.AreEqual(typeof(bool), expr.Type, "TypeIs#02"); Assert.AreEqual("(1 Is Int32)", expr.ToString(), "TypeIs#03"); }
/** * TypeBinaryExpression 表示表达式和类型之间的操作 * */ private void TestTypeBinaryExpression() { TypeBinaryExpression typeBinaryExpression = Expression.TypeIs(Expression.Constant("spruce"), typeof(int)); object obj = DBNull.Value; ParameterExpression value = Expression.Parameter(typeof(Object), "value"); var typeBinaryExpression2 = Expression.Block( new[] { value } //定义代码块中的变量 , Expression.Assign(value, Expression.Constant(obj))//给 value 赋值 , Expression.TypeIs(value, typeof(DBNull)) ); WriteLine(typeBinaryExpression.ToString()); // ("spruce" Is Int32) WriteLine(typeBinaryExpression2.Result); // (value Is DBNull) WriteLine(Expression.Lambda(typeBinaryExpression).Compile().DynamicInvoke()); WriteLine(Expression.Lambda(typeBinaryExpression2).Compile().DynamicInvoke()); }
/// <summary>访问子内容为: <see cref="T:System.Linq.Expressions.TypeBinaryExpression"></see>.</summary> /// <param name="node">被访问的表达式</param> /// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns> protected override Expression VisitTypeBinary(TypeBinaryExpression node) { Log(node.ToString()); throw new NotImplementedException(); }
public void UserDefinedClass() { TypeBinaryExpression expr = Expression.TypeIs(Expression.Constant(new OpClass()), typeof(OpClass)); Assert.AreEqual(ExpressionType.TypeIs, expr.NodeType, "TypeIs#07"); Assert.AreEqual(typeof(bool), expr.Type, "TypeIs#08"); Assert.AreEqual("(value(MonoTests.System.Linq.Expressions.OpClass) Is OpClass)", expr.ToString(), "TypeIs#09"); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { if (CommonUtil.IsClientType(b.Expression.Type)) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, SR.ALinqExpressionNotSupportedInProjection, this.type, b.ToString())); } return(base.VisitTypeIs(b)); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, SR.ALinqExpressionNotSupportedInProjectionToEntity, this.type, b.ToString())); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { if (CommonUtil.IsClientType(b.Expression.Type)) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, b.ToString())); } return(base.VisitTypeIs(b)); }
protected virtual Expression VisitTypeIs(TypeBinaryExpression node) { Console.WriteLine("VisitTypeIs:" + node.ToString()); return(node); }
public void ToStringTest() { TypeBinaryExpression e = Expression.TypeEqual(Expression.Parameter(typeof(string), "s"), typeof(string)); Assert.Equal("(s TypeEqual String)", e.ToString()); }
public void ToStringTest() { TypeBinaryExpression e = Expression.TypeIs(Expression.Parameter(typeof(object), "o"), typeof(string)); Assert.Equal("(o Is String)", e.ToString()); }
protected override Expression VisitTypeBinary(TypeBinaryExpression node) { Out(node.ToString()); return(node); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", type, b.ToString())); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, b.ToString())); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { if (ClientType.CheckElementTypeIsEntity(b.Expression.Type) || IsCollectionProducingExpression(b.Expression)) { throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjection(this.type, b.ToString())); } return(base.VisitTypeIs(b)); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { if (ClientTypeUtil.TypeOrElementTypeIsEntity(b.Expression.Type) || ProjectionAnalyzer.IsCollectionProducingExpression(b.Expression)) { throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, b.ToString())); } return(base.VisitTypeIs(b)); }