Browse by Tags
All Tags »
Expression Tree (
RSS)
Today I’ve encountered a strange problem running expressions - I wanted to created an expression tree that looks something like this: (e) => e.Owner != null && e.Owner.ID = 4455 So I’ve used the Expression.MakeBinary method to create a binary expression and passed it an ExpressionType.And enum, thinking this is the C# “&&” operator. When running the expression on an e instance that had no owner (null), I got an exception. When looking at the created expression it looked something...
MetaLinq project now supports serializing expression trees with XmlSerializer. For further information about this project, read my previous post on the subject.
I've blogged before (in hebrew) about the difficulty of serializing expression trees to XML. To conclude my hebrew post, I've found a project in CodePlex, called MetaLinq which might be the solution to the problem - this open source allows to perform Linq queries over expression trees, and as a consequence, might allow serialization of the navigable expression tree. I've worked in past few days to fix the code of the project to allow serializing the tree with DataContractSerializer. The...
אחד מהדברים השימושיים ב-3.0 #C, אע"פ שהוא מעט הוזנח במצגות השונות, הוא עץ הביטויים (Expression Tree) שהוא הדבק שמחבר את Lambda Expressions ו-Linq. מאחר ובאמצעות Expression Tree אפשר לייצג ביטוי לוגי, מצאתי לו שימוש במערכת בה הביטויים הלוגיים הם דינאמיים, המבנה שלהם נשמר ב-DB והם צריכים להיבנות ולהיבדק בזמן ריצה. אבל... בדבר אחד Expression Tree נכשל - אי אפשר לבצע לו סריאליזציה. הדבר מוסבר בפורומים השונים, כדוגמת כאן , והסיבות נשמעות די הגיוניות: המחלקות השונות של Expression Tree מכילות מאפיינים...
להלן בעיה - בהנתן Property כלשהו, נניח ששמו FirstName, עליכם להעביר למתודה את שם ה-Property כמחרוזת, תחת המגבלות הבאות: אינכם יכולים לרשום במפורש את שם ה-Property כמחרוזת ("FirstName") אינכם יכולים להשתמש ב-GetProperties, איכשהו לאתר את ה-PropertyInfo ולחלץ את שמו ממאפיין Name (לדוגמה - איתור ה-PropertyInfo הראשון שמתחיל ב-F ואורך שמו הוא 9) לפני כשנתיים נתקלתי בבעיה זו, כאשר וחיפשתי דרך לפתור את הבעיה שהוצגה בפוסט הקודם - העברה של שמות מאפיינים למתודה וקבלת ערכיהם (אז לא עלה בדעתי להשתמש...