Expression表达式资料

    xiaoxiao2024-12-03  3

    Expression创建对象

    http://www.cnblogs.com/coolcode/archive/2009/12/09/ExpressionCreateInstance.html

    Expression

    http://www.tuicool.com/articles/AZR3ua2

    MemberInitExpression 类

    可以动态构建对象 https://msdn.microsoft.com/zh-cn/library/system.linq.expressions.memberinitexpression.aspx class Animal { public string Species {get; set;} public int Age {get; set;} } public static void CreateMemberInitExpression() { System.Linq.Expressions.NewExpression newAnimal = System.Linq.Expressions.Expression.New(typeof(Animal)); System.Reflection.MemberInfo speciesMember = typeof(Animal).GetMember("Species")[0]; System.Reflection.MemberInfo ageMember = typeof(Animal).GetMember("Age")[0]; // Create a MemberBinding object for each member // that you want to initialize. System.Linq.Expressions.MemberBinding speciesMemberBinding = System.Linq.Expressions.Expression.Bind( speciesMember, System.Linq.Expressions.Expression.Constant("horse")); System.Linq.Expressions.MemberBinding ageMemberBinding = System.Linq.Expressions.Expression.Bind( ageMember, System.Linq.Expressions.Expression.Constant(12)); // Create a MemberInitExpression that represents initializing // two members of the 'Animal' class. System.Linq.Expressions.MemberInitExpression memberInitExpression = System.Linq.Expressions.Expression.MemberInit( newAnimal, speciesMemberBinding, ageMemberBinding); Console.WriteLine(memberInitExpression.ToString()); // This code produces the following output: // // new Animal() {Species = "horse", Age = 12} } 使用Expression Tree构建带有参数、本地变量和返回值的Lambda http://blog.csdn.net/cauchy8389/article/details/23529857

    转载请注明原文地址: https://ju.6miu.com/read-1294213.html
    最新回复(0)