{"id":3953,"date":"2014-03-30T06:39:40","date_gmt":"2014-03-30T06:39:40","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/best-way-to-evaluate-string-conditions-like-user-name-length0-as-true-or-false-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:39:40","modified_gmt":"2014-03-30T06:39:40","slug":"best-way-to-evaluate-string-conditions-like-user-name-length0-as-true-or-false-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/best-way-to-evaluate-string-conditions-like-user-name-length0-as-true-or-false-collection-of-common-programming-errors\/","title":{"rendered":"Best way to evaluate string conditions like &ldquo;User.Name.Length&gt;0&rdquo; as true or false?-Collection of common programming errors"},"content":{"rendered":"<p>What is the best way to evaluate at runtime conditional expressions which are stored as strings.<\/p>\n<p>I am using MVC3, .NET4, C#4.<\/p>\n<p>So assume the solution was a method called &#8220;Eval&#8221; then:<\/p>\n<pre><code>if eval(\"User.Name.Length&gt;0\")\n{return true;}\n<\/code><\/pre>\n<p>should behave in the same way as:<\/p>\n<pre><code>if (User.Name.Length&gt;0)\n{return true;}\n<\/code><\/pre>\n<p>So I need to also access any inscope .NET types as part of this solution.<\/p>\n<p>So what would be a solution for &#8220;Eval&#8221;?<\/p>\n<p>Thanks.<\/p>\n<p>P.S I had posted a seperate question on this focusing on Dynamic LINQ as the solution. However I now think my solution is more simple, hence this question.<\/p>\n<p>EDIT. Do not read too much into the &#8220;User&#8221;. It could be any object. I am interested in how to evaluate string expressions at runtime as if they had been written explicitely at compile time. Another example might be:<\/p>\n<pre><code>if eval(\"mycat.coatcolour=='ginger'\")\n{return true;}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is the best way to evaluate at runtime conditional expressions which are stored as strings. I am using MVC3, .NET4, C#4. So assume the solution was a method called &#8220;Eval&#8221; then: if eval(&#8220;User.Name.Length&gt;0&#8221;) {return true;} should behave in the same way as: if (User.Name.Length&gt;0) {return true;} So I need to also access any inscope [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3953","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3953"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3953\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}