//泛型反射 FjUe FjXk1() { Type type = typeof(Action <,>).MakeGenericType(typeof(FjUeObj), typeof(Guid)); Delegate dele = Delegate.CreateDelegate(type, typeof(FjUeObj).GetProperty("Guid").SetMethod); Console.WriteLine("dele is Action<FjUeObj,Guid> ? " + (dele is Action <FjUeObj, Guid>)); var obj = new FjUeObj(); ((Action <FjUeObj, Guid>)dele)(obj, Guid.NewGuid()); return(this); }
FjUe Expression3() { var pInstance = Expression.Parameter(typeof(FjUeObj), "instance"); var body = Expression.Assign( Expression.Property(pInstance, "Name"), Expression.Constant("111")); var lambda = Expression.Lambda <Action <FjUeObj> >(body, pInstance); var fun = lambda.Compile(); var fjueObj = new FjUeObj { Name = "AA", Qty = 20 }; fun(fjueObj); return(this); }