{"id":51,"date":"2024-07-12T15:15:02","date_gmt":"2024-07-12T13:15:02","guid":{"rendered":"https:\/\/mesbahi.net\/en\/?p=51"},"modified":"2024-07-12T15:15:37","modified_gmt":"2024-07-12T13:15:37","slug":"expression-trees-2-creating-a-business-rule-engine","status":"publish","type":"post","link":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/","title":{"rendered":"Expression Trees 2: Creating a Business Rule Engine"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\" id=\"ember1383\">In the <a href=\"https:\/\/www.linkedin.com\/pulse\/expression-trees-1-big-picture-amin-mesbahi-qddof\/?trackingId=aEvnS9HIRma4Vlh40eG3SQ%3D%3D\">previous post<\/a>, I covered the basics of expression trees, including their structure and how to create them in .NET. Now, let&#8217;s dive into a real-world example: building a simple Business Rule Engine (BRE) using expression trees. This engine will apply discount rules based on certain conditions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1384\">Scenario: Discount Calculation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1385\">Imagine you are working on an e-commerce platform, and you need to implement a business rule engine (BRE) system, and one of its features is to calculate discounts based on various business rules. These rules might include conditions like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the customer is a premium member AND the order amount is greater than $100, apply a 10% discount.<\/li>\n\n\n\n<li>If the order contains more than 5 items OR the order amount is greater than $200, apply a 5% discount.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1387\">Building the Business Rule Engine<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1388\">We&#8217;ll build a <strong>modular <\/strong>Business Rule Engine that evaluates these conditions dynamically using expression trees. (using expressions, we can make cleaner, more maintainable, and performant code)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1389\">Step 1: Define the Data Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1390\">First, let&#8217;s define our data model for orders and customers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Order\n{\n    public decimal Amount { get; set; }\n    public int ItemCount { get; set; }\n    public bool IsPremiumMember { get; set; }\n} <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1391\">Step 2: Define the Rule Structure<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1392\">Next, we&#8217;ll define the structure for our discount rules.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class DiscountRule\n{\n    public Expression&lt;Func&lt;Order, bool&gt;&gt; Condition { get; set; }\n    public decimal DiscountPercentage { get; set; }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1393\">Step 3: Create the Rule Engine<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1394\">We&#8217;ll create a class to manage and evaluate these rules.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class RuleEngine\n{\n    private readonly List&lt;DiscountRule&gt; _rules = new List&lt;DiscountRule&gt;();\n\n    public void AddRule(DiscountRule rule)\n    {\n        _rules.Add(rule);\n    }\n\n    public decimal CalculateDiscount(Order order)\n    {\n        foreach (var rule in _rules)\n        {\n            var compiledCondition = rule.Condition.Compile();\n            if (compiledCondition(order))\n            {\n                return rule.DiscountPercentage;\n            }\n        }\n        return 0;\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1395\">Step 4: Define the Discount Rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1396\">Now let&#8217;s define our discount rules using expression trees.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.Linq.Expressions;\n\nclass Program\n{\n    static void Main()\n    {\n        var ruleEngine = new RuleEngine();\n\n        \/\/ Rule 1: If the customer is a premium member AND the order amount is greater than $100, apply a 10% discount.\n        var rule1 = new DiscountRule\n        {\n            Condition = order =&gt; order.IsPremiumMember &amp;&amp; order.Amount &gt; 100,\n            DiscountPercentage = 10\n        };\n\n        \/\/ Rule 2: If the order contains more than 5 items OR the order amount is greater than $200, apply a 5% discount.\n        var rule2 = new DiscountRule\n        {\n            Condition = order =&gt; order.ItemCount &gt; 5 || order.Amount &gt; 200,\n            DiscountPercentage = 5\n        };\n\n        ruleEngine.AddRule(rule1);\n        ruleEngine.AddRule(rule2);\n\n        \/\/ Example order\n        var order = new Order\n        {\n            Amount = 150,\n            ItemCount = 3,\n            IsPremiumMember = true\n        };\n\n        decimal discount = ruleEngine.CalculateDiscount(order);\n        Console.WriteLine($\"Discount: {discount}%\"); \/\/ Output: Discount: 10%\n    }\n} <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1397\">Benefits of Using Expression Trees<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Flexibility<\/strong>: Easily define and modify business rules without changing the core logic.<\/li>\n\n\n\n<li><strong>Dynamic Evaluation<\/strong>: Compile and evaluate conditions at runtime.<\/li>\n\n\n\n<li><strong>Modularity<\/strong>: Add or remove rules as needed without affecting other parts of the system.<\/li>\n\n\n\n<li><strong>Performance:<\/strong> A compiled code can be run faster<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1399\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1400\">By leveraging expression trees, we can build a flexible and modular Business Rule Engine that dynamically evaluates complex conditions. This approach not only simplifies the implementation of business logic but also enhances maintainability and scalability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1401\">Stay tuned!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous post, I covered the basics of expression trees, including their structure and how to create them in .NET. Now, let&#8217;s dive into a real-world example: building a simple Business Rule Engine (BRE) using expression trees. This engine will apply discount rules based on certain conditions. Scenario: Discount Calculation Imagine you are working &#8230; <a title=\"Expression Trees 2: Creating a Business Rule Engine\" class=\"read-more\" href=\"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/\" aria-label=\"Read more about Expression Trees 2: Creating a Business Rule Engine\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":52,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[10],"tags":[8,7,9],"class_list":["post-51","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development","tag-c","tag-expression-tree","tag-software-engineering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Expression Trees 2: Creating a Business Rule Engine - Amin Notes<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Expression Trees 2: Creating a Business Rule Engine - Amin Notes\" \/>\n<meta property=\"og:description\" content=\"In the previous post, I covered the basics of expression trees, including their structure and how to create them in .NET. Now, let&#8217;s dive into a real-world example: building a simple Business Rule Engine (BRE) using expression trees. This engine will apply discount rules based on certain conditions. Scenario: Discount Calculation Imagine you are working ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/\" \/>\n<meta property=\"og:site_name\" content=\"Amin Notes\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-12T13:15:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-12T13:15:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1232\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Amin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/\"},\"author\":{\"name\":\"Amin\",\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/#\\\/schema\\\/person\\\/4dbd4832b7ddc555c3007c965ed80827\"},\"headline\":\"Expression Trees 2: Creating a Business Rule Engine\",\"datePublished\":\"2024-07-12T13:15:02+00:00\",\"dateModified\":\"2024-07-12T13:15:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/\"},\"wordCount\":311,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/07\\\/TfK7aYGATNqB279dheYGLQ.webp\",\"keywords\":[\"c#\",\"expression tree\",\"software engineering\"],\"articleSection\":[\"Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/\",\"url\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/\",\"name\":\"Expression Trees 2: Creating a Business Rule Engine - Amin Notes\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/07\\\/TfK7aYGATNqB279dheYGLQ.webp\",\"datePublished\":\"2024-07-12T13:15:02+00:00\",\"dateModified\":\"2024-07-12T13:15:37+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/#\\\/schema\\\/person\\\/4dbd4832b7ddc555c3007c965ed80827\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#primaryimage\",\"url\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/07\\\/TfK7aYGATNqB279dheYGLQ.webp\",\"contentUrl\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/07\\\/TfK7aYGATNqB279dheYGLQ.webp\",\"width\":1232,\"height\":768},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/2024\\\/07\\\/12\\\/expression-trees-2-creating-a-business-rule-engine\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Expression Trees 2: Creating a Business Rule Engine\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/\",\"name\":\"Amin Notes\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/#\\\/schema\\\/person\\\/4dbd4832b7ddc555c3007c965ed80827\",\"name\":\"Amin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/61f446bd7d862db2d26d17175d1fd98d75d04d12ab658db9af0fb94b837a98d7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/61f446bd7d862db2d26d17175d1fd98d75d04d12ab658db9af0fb94b837a98d7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/61f446bd7d862db2d26d17175d1fd98d75d04d12ab658db9af0fb94b837a98d7?s=96&d=mm&r=g\",\"caption\":\"Amin\"},\"url\":\"https:\\\/\\\/mesbahi.net\\\/en\\\/author\\\/en\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Expression Trees 2: Creating a Business Rule Engine - Amin Notes","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/","og_locale":"en_US","og_type":"article","og_title":"Expression Trees 2: Creating a Business Rule Engine - Amin Notes","og_description":"In the previous post, I covered the basics of expression trees, including their structure and how to create them in .NET. Now, let&#8217;s dive into a real-world example: building a simple Business Rule Engine (BRE) using expression trees. This engine will apply discount rules based on certain conditions. Scenario: Discount Calculation Imagine you are working ... Read more","og_url":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/","og_site_name":"Amin Notes","article_published_time":"2024-07-12T13:15:02+00:00","article_modified_time":"2024-07-12T13:15:37+00:00","og_image":[{"width":1232,"height":768,"url":"https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp","type":"image\/webp"}],"author":"Amin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Amin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#article","isPartOf":{"@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/"},"author":{"name":"Amin","@id":"https:\/\/mesbahi.net\/en\/#\/schema\/person\/4dbd4832b7ddc555c3007c965ed80827"},"headline":"Expression Trees 2: Creating a Business Rule Engine","datePublished":"2024-07-12T13:15:02+00:00","dateModified":"2024-07-12T13:15:37+00:00","mainEntityOfPage":{"@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/"},"wordCount":311,"commentCount":0,"image":{"@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#primaryimage"},"thumbnailUrl":"https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp","keywords":["c#","expression tree","software engineering"],"articleSection":["Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/","url":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/","name":"Expression Trees 2: Creating a Business Rule Engine - Amin Notes","isPartOf":{"@id":"https:\/\/mesbahi.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#primaryimage"},"image":{"@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#primaryimage"},"thumbnailUrl":"https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp","datePublished":"2024-07-12T13:15:02+00:00","dateModified":"2024-07-12T13:15:37+00:00","author":{"@id":"https:\/\/mesbahi.net\/en\/#\/schema\/person\/4dbd4832b7ddc555c3007c965ed80827"},"breadcrumb":{"@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#primaryimage","url":"https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp","contentUrl":"https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp","width":1232,"height":768},{"@type":"BreadcrumbList","@id":"https:\/\/mesbahi.net\/en\/2024\/07\/12\/expression-trees-2-creating-a-business-rule-engine\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mesbahi.net\/en\/"},{"@type":"ListItem","position":2,"name":"Expression Trees 2: Creating a Business Rule Engine"}]},{"@type":"WebSite","@id":"https:\/\/mesbahi.net\/en\/#website","url":"https:\/\/mesbahi.net\/en\/","name":"Amin Notes","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mesbahi.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mesbahi.net\/en\/#\/schema\/person\/4dbd4832b7ddc555c3007c965ed80827","name":"Amin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/61f446bd7d862db2d26d17175d1fd98d75d04d12ab658db9af0fb94b837a98d7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/61f446bd7d862db2d26d17175d1fd98d75d04d12ab658db9af0fb94b837a98d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/61f446bd7d862db2d26d17175d1fd98d75d04d12ab658db9af0fb94b837a98d7?s=96&d=mm&r=g","caption":"Amin"},"url":"https:\/\/mesbahi.net\/en\/author\/en\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp",1232,768,false],"thumbnail":["https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ-150x150.webp",150,150,true],"medium":["https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ-300x187.webp",300,187,true],"medium_large":["https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ-768x479.webp",768,479,true],"large":["https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ-1024x638.webp",1024,638,true],"1536x1536":["https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp",1232,768,false],"2048x2048":["https:\/\/mesbahi.net\/en\/wp-content\/uploads\/sites\/2\/2024\/07\/TfK7aYGATNqB279dheYGLQ.webp",1232,768,false]},"uagb_author_info":{"display_name":"Amin","author_link":"https:\/\/mesbahi.net\/en\/author\/en\/"},"uagb_comment_info":0,"uagb_excerpt":"In the previous post, I covered the basics of expression trees, including their structure and how to create them in .NET. Now, let&#8217;s dive into a real-world example: building a simple Business Rule Engine (BRE) using expression trees. This engine will apply discount rules based on certain conditions. Scenario: Discount Calculation Imagine you are working&hellip;","_links":{"self":[{"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":1,"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/posts\/51\/revisions\/53"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/media\/52"}],"wp:attachment":[{"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mesbahi.net\/en\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}