{"id":39,"date":"2008-08-07T12:01:23","date_gmt":"2008-08-07T11:01:23","guid":{"rendered":"https:\/\/ridgesolutions.ie\/?p=39"},"modified":"2009-01-12T18:22:48","modified_gmt":"2009-01-12T17:22:48","slug":"programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30","status":"publish","type":"post","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/","title":{"rendered":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0"},"content":{"rendered":"<p>As part of a project that we are working on at the moment\u00a0 we need a way of converting a literal or constant into a lambda expression which when evaluated will\u00a0yield the original literal value (in c#).\u00a0 This must work in the same way for multiple types.<\/p>\n<p>\u00a0<\/p>\n<p>For example given the literal string &#8220;hello&#8221; we need to programmatically create the lambda<\/p>\n<p>\u00a0<\/p>\n<p style=\"PADDING-LEFT: 30px\">() =&gt; &#8220;hello&#8221;<\/p>\n<p style=\"PADDING-LEFT: 30px\">\u00a0<\/p>\n<p>and for the boolean true we want to create:<\/p>\n<p>\u00a0<\/p>\n<p style=\"PADDING-LEFT: 30px\">() =&gt; true<\/p>\n<p style=\"PADDING-LEFT: 30px\">\u00a0<\/p>\n<p>etc.<\/p>\n<p>\u00a0<\/p>\n<p>This can be achieved by creating an appropriate expression tree and then compiling it into a lambda expression, and as we want this to work for different types we wrap all of this into a generic function like the following:<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 static public Func&lt;T&gt; ToLambda&lt;T&gt;(T val)<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ConstantExpression body = Expression.Constant(val);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LambdaExpression exp = Expression.Lambda&lt;Func&lt;T&gt;&gt;(body, null);<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return (Func&lt;T&gt;)exp.Compile();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p>\u00a0<\/p>\n<p>The function takes the value in question as type T and returns a\u00a0parameter-less delegate of return\u00a0type T.\u00a0 It\u00a0uses the passed value to create a ConstantExpression,\u00a0and then uses it to create a LambdaExpression, as the required lambda has no paramters it passes &#8216;null&#8217; into the constructor&#8217;s second parameter.\u00a0 Now all that is left is to compile the LambdaExpression, this creates and returns the required delegate which is then returned.<\/p>\n<p>\u00a0<\/p>\n<p>The following code shows the\u00a0lambda generator\u00a0in action:<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 static public void TestLiteralToLambda()<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Create the Lambda from literal<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var boolLambda = ToLambda(true);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Evaluate the lambda..<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 bool boolVal = boolLambda();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ and, log out some info<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Console.WriteLine(&#8220;Lambda evaluates to &#8211; {0}&#8221;, boolVal);<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var stringLambda = ToLambda(&#8220;Rainy day in Dublin&#8221;);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 string stringVal = stringLambda();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Console.WriteLine(&#8220;Lambda evaluates to &#8211; {0}&#8221;, stringVal);<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var doubleLambda = ToLambda(3.14159);<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 double doubleVal = doubleLambda();<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Console.WriteLine(&#8220;Lambda evaluates to &#8211; {0}&#8221;, doubleVal);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0?<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p>\u00a0<\/p>\n<p>So far, so good.\u00a0 Although this might seem a little strange and vaguely useless, what it allows us to do is to treat literals and lambdas of the same type in exactly the same way.<\/p>\n<p>\u00a0<\/p>\n<p>Specifically what we want to be able to do is to define &#8216;super properties&#8217; on objects whose values when queried are either regular values (as normal) or are the result of evaluating a rule, this rule being provided as a lambda expression.\u00a0 When the property&#8217;s value is set the programmer either provides a value (literal or constant) or a rule (lambda expression).<\/p>\n<p>\u00a0<\/p>\n<p>Further details\u00a0on the exact makeup of\u00a0these &#8216;super properties&#8217; elude us at the moment, more later&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of a project that we are working on at the moment\u00a0 we need a way of converting a literal or constant into a lambda expression which when evaluated will\u00a0yield the original literal value (in c#).\u00a0 This must work in the same way for multiple types. \u00a0 For example given the literal string &#8220;hello&#8221; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[11,12],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-tech-stuff","tag-cplusplus","tag-lambda-expression"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string &quot;hello&quot;\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Kevin Godden\"\/>\n\t<meta name=\"google-site-verification\" content=\"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0\" \/>\n\t\t<meta property=\"og:description\" content=\"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string &quot;hello&quot;\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-08-07T11:01:23+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2009-01-12T17:22:48+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0\" \/>\n\t\t<meta name=\"twitter:description\" content=\"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string &quot;hello&quot;\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#article\",\"name\":\"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0\",\"headline\":\"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0\",\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#articleImage\",\"width\":400,\"height\":81},\"datePublished\":\"2008-08-07T12:01:23+00:00\",\"dateModified\":\"2009-01-12T18:22:48+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#webpage\"},\"articleSection\":\"Tech Stuff, c++, lambda\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"name\":\"Tech Stuff\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"position\":2,\"name\":\"Tech Stuff\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#listItem\",\"name\":\"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#listItem\",\"position\":3,\"name\":\"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/tech-stuff\\\/#listItem\",\"name\":\"Tech Stuff\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#organizationLogo\",\"width\":400,\"height\":81},\"image\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/\",\"name\":\"Kevin Godden\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Kevin Godden\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#webpage\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/\",\"name\":\"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0\",\"description\":\"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string \\\"hello\\\"\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/07\\\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"datePublished\":\"2008-08-07T12:01:23+00:00\",\"dateModified\":\"2009-01-12T18:22:48+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","description":"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string \"hello\"","canonical_url":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"google-site-verification":"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#article","name":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","headline":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/#articleImage","width":400,"height":81},"datePublished":"2008-08-07T12:01:23+00:00","dateModified":"2009-01-12T18:22:48+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#webpage"},"isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#webpage"},"articleSection":"Tech Stuff, c++, lambda"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","position":1,"name":"Home","item":"https:\/\/www.ridgesolutions.ie","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","name":"Tech Stuff"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","position":2,"name":"Tech Stuff","item":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#listItem","name":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#listItem","position":3,"name":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/#listItem","name":"Tech Stuff"}}]},{"@type":"Organization","@id":"https:\/\/www.ridgesolutions.ie\/#organization","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","url":"https:\/\/www.ridgesolutions.ie\/","logo":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#organizationLogo","width":400,"height":81},"image":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author","url":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/","name":"Kevin Godden","image":{"@type":"ImageObject","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g","width":96,"height":96,"caption":"Kevin Godden"}},{"@type":"WebPage","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#webpage","url":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/","name":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","description":"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string \"hello\"","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/#website"},"breadcrumb":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/#breadcrumblist"},"author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"creator":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"datePublished":"2008-08-07T12:01:23+00:00","dateModified":"2009-01-12T18:22:48+00:00"},{"@type":"WebSite","@id":"https:\/\/www.ridgesolutions.ie\/#website","url":"https:\/\/www.ridgesolutions.ie\/","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"}}]},"og:locale":"en_US","og:site_name":"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer","og:type":"article","og:title":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","og:description":"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string &quot;hello&quot;","og:url":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/","article:published_time":"2008-08-07T11:01:23+00:00","article:modified_time":"2009-01-12T17:22:48+00:00","twitter:card":"summary","twitter:title":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","twitter:description":"As part of a project that we are working on at the moment we need a way of converting a literal or constant into a lambda expression which when evaluated will yield the original literal value (in c#). This must work in the same way for multiple types. For example given the literal string &quot;hello&quot;"},"aioseo_meta_data":{"post_id":"39","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-09-13 21:32:18","updated":"2025-07-15 20:25:50","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/\" title=\"Tech Stuff\">Tech Stuff<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tProgramatically Converting a Literal into an equivalent Lambda Expression in c#3.0\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.ridgesolutions.ie"},{"label":"Tech Stuff","link":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/tech-stuff\/"},{"label":"Programatically Converting a Literal into an equivalent Lambda Expression in c#3.0","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/07\/programatically-converting-a-literal-into-an-equivalent-lambda-expression-in-c30\/"}],"_links":{"self":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":0,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}