مجموعه 3 قسمتی از مفاهیم Expression Tree در سی شارپ
200, OK
https://www.youtube.com/playlist?list=PLN5rV4x2x5Xc_A6UwalFsX6XkMkX7fcAE icon

مباحث 

  • #statement and expression in c 
  • delegates 
  • delegate instance 
  • Func
  • lambda expression 
  • lambda expression return type in c# 10 
  • captured value
  • static lambda 
  • IEnumerable, IQueryable 
  • description of Expression Tree 
  • Writing Expression Tree 
  • Where and Order by and ... Decorator 
  •  Chaining decorator 
  • Query Execution 
  • Inside of IQueryable 
  • Expression Visitor 

مجموعه 3 قسمتی از مفاهیم Expression Tree  در سی شارپ
کار با Expression Tree در سی شارپ
308, PermanentRedirect
https://tyrrrz.me:443/blog/expression-trees/ icon


میشه گفت یکی از advanced‌ترین قسمت‌های دات نت، مفهوم Expression Tree و کلاس Expression هست که یه جورایی قلب IQueryable رو هم تشکیل میده

شاید نهایت استفاده افراد، کار با <<Expression<Func برای شرط‌های predicate بر روی متد Where و یا selector برای متد Select باشه

ولی Expression خیلی بزرگتر از اینهاست 

توضیح مفهوم Expression Tree طولانیه اگه میخواین بیشتر باهاش اشنا بشین قبلا اینجا یه پست نوشتم براش.

لینک اشتراک جاری هم یکی از بهترین مقالاتی که این مفهوم رو به خوبی به همراه مثال توضیح داده

کار با Expression Tree در سی شارپ
تولید شرط های پویا توسط کتابخانه LambdaExpressionBuilder
200, OK
https://github.com/dbelmont/ExpressionBuilder icon

A library that provides a simple way to create lambda expressions to filter lists and database queries. 

var filter = new Filter<Person>();
filter.By("Id", Operation.Between, 2, 4,  Connector.And);
filter.By("Contacts[Value]", Operation.EndsWith, "@email.com", default(string), Connector.And);
filter.By("Birth.Country", Operation.IsNotNull, default(string), default(string),  Connector.Or);
filter.By("Name", Operation.Contains, " John");
var people = People.Where(filter);

//or like this...

var filter = new Filter<Person>();
filter.By("Id", Operation.Between, 2, 4)
      .And.By("Birth.Country", Operation.IsNotNull)
      .And.By("Contacts[Value]", Operation.EndsWith, "@email.com")
      .Or.By("Name", Operation.Contains, " John ");
var people = People.Where(filter);

So that would generate an expression like this: 

People.Where(p => (p.Id >= 2 && p.Id <= 4)
             && (p.Birth != null && p.Birth.Country != null)
             && (p.Contacts != null && p.Contacts.Any(c => c.Value.Trim().ToLower().EndsWith("@email.com")))
             || (p.Name != null  && p.Name.Trim().ToLower().Contains("john")));

LambdaExpressionBuilder Nuget Package 

تولید شرط های پویا توسط کتابخانه LambdaExpressionBuilder