dynamic-language-runtime

Expression.Lambda and query generation at runtime, simplest “Where” example

前提是你 提交于 2019-11-26 21:30:45
I was trying to generate a simple Lambda Expression at runtime with no luck... something like this: var result = queryableData.Where(item => item.Name == "Soap") Here is my example class and a fixture queryable: public class Item { public int Id { get; set; } public string Name { get; set; } } IQueryable<Item> queryableData = ...; Then I generate a lambda expression at runtime correct code follows : //"item" in "item =>..." var item = Expression .Parameter(typeof(Item), "item"); //property of my item, this is "item.Name" var prop = Expression .Property(item, "Name"); //then "Soap" in '... =>

Dynamically adding members to a dynamic object

南楼画角 提交于 2019-11-26 20:44:19
问题 I'm looking for a way to add members dynamically to an dynamic object. OK, I guess a little clarification is needed... When you do that : dynamic foo = new ExpandoObject(); foo.Bar = 42; The Bar property will be added dynamically at runtime. But the code still refers "statically" to Bar (the name "Bar" is hard-coded)... What if I want to add a property at runtime without knowing its name at compile time ? I know how to do this with a custom dynamic object (I actually blogged about it a few

Dynamic Lang. Runtime vs Reflection

不羁岁月 提交于 2019-11-26 10:25:31
问题 I am planning to use dynamic keyword for my new project. But before stepping in, I would like to know about the pros and cons in using dynamic keyword over Reflection. Following where the pros, I could find in respect to dynamic keyword: Readable\\Maintainable code. Fewer lines of code. While the negatives associated with using dynamic keyword, I came to hear was like: Affects application performance. Dynamic keyword is internally a wrapper of Reflection. Dynamic typing might turn into

Expression.Lambda and query generation at runtime, simplest “Where” example

穿精又带淫゛_ 提交于 2019-11-26 07:57:40
问题 I was trying to generate a simple Lambda Expression at runtime with no luck... something like this: var result = queryableData.Where(item => item.Name == \"Soap\") Here is my example class and a fixture queryable: public class Item { public int Id { get; set; } public string Name { get; set; } } IQueryable<Item> queryableData = ...; Then I generate a lambda expression at runtime correct code follows : //\"item\" in \"item =>...\" var item = Expression .Parameter(typeof(Item), \"item\"); /