{"id":40,"date":"2008-08-12T10:23:52","date_gmt":"2008-08-12T09:23:52","guid":{"rendered":"https:\/\/ridgesolutions.ie\/?p=40"},"modified":"2009-01-12T18:23:24","modified_gmt":"2009-01-12T17:23:24","slug":"implicit-cast-of-lambda-expression-to-custom-class-in-c-30","status":"publish","type":"post","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/","title":{"rendered":"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?"},"content":{"rendered":"<p>We\u00a0hit a little speed bump\u00a0in our\u00a0work with\u00a0parameter-less\u00a0lambdas\u00a0&#8211; we\u00a0wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan&#8230;<\/p>\n<p>\u00a0<\/p>\n<p>To illustrate this consider the following class that just encapsulates a 0-arity delegate Func&lt;T&gt;:<\/p>\n<pre>\u00a0\u00a0\u00a0 public class RuleProp&lt;T&gt;\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 private Func&lt;T&gt; _lambda = null;<\/pre>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public RuleProp(Func&lt;T&gt; l)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _lambda = l;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/pre>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static implicit operator RuleProp&lt;T&gt;(Func&lt;T&gt; l)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return new RuleProp&lt;T&gt;(l);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/pre>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public RuleProp()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 }<\/pre>\n<p>Now, because we have specified an implicit cast for: Func&lt;T&gt; -&gt; RuleProp&lt;T&gt;, it would seem \u00a0that we should be able to do the following:<\/p>\n<pre>var rp = new RuleProp&lt;string&gt;();\r\nrp = () =&gt; \"hello\"; \/\/ Not OK, can't convert lambda to delegate\u00a0<\/pre>\n<p>But this gives us a compiler error, can&#8217;t convert lambda to Fun&lt;T&gt; as it&#8217;s not a delegate!!\u00a0 Looking at the C# specification it seems that if more than one implicit conversion is required, the C# compiler will only do one.\u00a0 In this case 2 conversions are required:<\/p>\n<p>\u00a0<\/p>\n<p>Lambda Expression -&gt; Func&lt;T&gt; -&gt; RuleProp&lt;T&gt;<\/p>\n<p>\u00a0<\/p>\n<p>And so the compiler can&#8217;t handle it.\u00a0 If we provide an explicit cast to Func&lt;T&gt; it compiles OK:<\/p>\n<p>\u00a0<\/p>\n<pre>rp = (Func&lt;string&gt;)(() =&gt; \"hello\");\u00a0 \/\/ Cast works..<\/pre>\n<p>\u00a0<\/p>\n<p>But this is really ugly as the type must be provided each time.\u00a0 A workaround was suggested in this article:<\/p>\n<p>\u00a0<\/p>\n<p><a href=\"http:\/\/www.interact-sw.co.uk\/iangblog\/2008\/03\/17\/lambda-inference\"><span style=\"color: #0072bc;\">http:\/\/www.interact-sw.co.uk\/iangblog\/2008\/03\/17\/lambda-inference<\/span><\/a><\/p>\n<p>\u00a0<\/p>\n<p>We provide an &#8216;adaptor&#8217; function which encourages a cast from Lambda -&gt; Func&lt;T&gt;, and the implicit cast from Func&lt;T&gt; to RuleProp&lt;T&gt; will handle the rest, we can use it like this:<\/p>\n<p>\u00a0<\/p>\n<pre>rp = Adaptor(() =&gt; \"hello\");\u00a0 \/\/ Now OK!<\/pre>\n<p>This is much nicer than the explicit cast as no type needs to be specified!\u00a0 Here is the function, it just take,s and directly returns a delegate &#8211;\u00a0resulting in just the conversion that we need!<\/p>\n<p>\u00a0<\/p>\n<pre>public static Func&lt;T&gt; Adaptor&lt;T&gt;(Func&lt;T&gt; f)\r\n{\r\n\u00a0return f;\r\n}<\/pre>\n<p>\u00a0<\/p>\n<p>So although it is not as nice as directly assigning a lambda to RuleProp&lt;T&gt; it&#8217;s a grand workaround and will do nicely for the time being &#8211; thanks to all at the <a href=\"http:\/\/forums.msdn.microsoft.com\/en-US\/tag\/visualcsharp\/\">C# MSDN<\/a> forum for their help!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u00a0hit a little speed bump\u00a0in our\u00a0work with\u00a0parameter-less\u00a0lambdas\u00a0&#8211; we\u00a0wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan&#8230; \u00a0 To illustrate this consider the following class that just encapsulates a 0-arity delegate Func&lt;T&gt;: \u00a0\u00a0\u00a0 public class RuleProp&lt;T&gt; \u00a0\u00a0\u00a0 { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 private [&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-40","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=\"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private\" \/>\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\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/\" \/>\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=\"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?\" \/>\n\t\t<meta property=\"og:description\" content=\"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-08-12T09:23:52+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2009-01-12T17:23:24+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?\" \/>\n\t\t<meta name=\"twitter:description\" content=\"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private\" \/>\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\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#article\",\"name\":\"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?\",\"headline\":\"Implicit Cast of Lambda Expression to Custom Class 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-12T10:23:52+00:00\",\"dateModified\":\"2009-01-12T18:23:24+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#webpage\"},\"articleSection\":\"Tech Stuff, c++, lambda\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#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\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#listItem\",\"name\":\"Implicit Cast of Lambda Expression to Custom Class 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\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#listItem\",\"position\":3,\"name\":\"Implicit Cast of Lambda Expression to Custom Class 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\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#organizationLogo\",\"width\":400,\"height\":81},\"image\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#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\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#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\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#webpage\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/\",\"name\":\"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?\",\"description\":\"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2008\\\/08\\\/12\\\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\\\/#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-12T10:23:52+00:00\",\"dateModified\":\"2009-01-12T18:23:24+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":"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?","description":"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private","canonical_url":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/","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\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#article","name":"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?","headline":"Implicit Cast of Lambda Expression to Custom Class 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-12T10:23:52+00:00","dateModified":"2009-01-12T18:23:24+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#webpage"},"isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#webpage"},"articleSection":"Tech Stuff, c++, lambda"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#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\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#listItem","name":"Implicit Cast of Lambda Expression to Custom Class 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\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#listItem","position":3,"name":"Implicit Cast of Lambda Expression to Custom Class 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\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#organizationLogo","width":400,"height":81},"image":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#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\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#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\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#webpage","url":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/","name":"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?","description":"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/#website"},"breadcrumb":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/#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-12T10:23:52+00:00","dateModified":"2009-01-12T18:23:24+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":"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?","og:description":"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private","og:url":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/","article:published_time":"2008-08-12T09:23:52+00:00","article:modified_time":"2009-01-12T17:23:24+00:00","twitter:card":"summary","twitter:title":"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?","twitter:description":"We hit a little speed bump in our work with parameter-less lambdas - we wanted to be able to assign them to objects of a custom class via an implicit cast, this is very important to our cunning plan... To illustrate this consider the following class that just encapsulates a 0-arity delegate Func: public class RuleProp { private"},"aioseo_meta_data":{"post_id":"40","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 12:52:58","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\tImplicit Cast of Lambda Expression to Custom Class 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":"Implicit Cast of Lambda Expression to Custom Class in C# 3.0?","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2008\/08\/12\/implicit-cast-of-lambda-expression-to-custom-class-in-c-30\/"}],"_links":{"self":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/40","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=40"}],"version-history":[{"count":0,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}