tag:blogger.com,1999:blog-5185363813089043049.post6355753932398232251..comments2024-02-09T15:46:29.925+10:00Comments on <a href="http://gratdevel.blogspot.com"> Gratuitous Development </a>: c# Linq Compound FromsAnonymoushttp://www.blogger.com/profile/01511624047365507765noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5185363813089043049.post-17391239220248239532022-04-17T08:06:54.004+10:002022-04-17T08:06:54.004+10:00Great blog, thanks for posting this.Great blog, thanks for posting this.Myahttps://www.myamurphy.com/noreply@blogger.comtag:blogger.com,1999:blog-5185363813089043049.post-84875872042755760912012-05-03T07:47:08.618+10:002012-05-03T07:47:08.618+10:00"from/SelectMany" in linq is just the mo..."from/SelectMany" in linq is just the monadic bind operator. In typical linq, you're just using the List monad. But you can also create your own SelectMany and thereby create your own monadic syntax as well. It's pretty cool -- google around for how to make the Maybe monad in LINQ. Probably 20-30 lines of code and you can avoid null reference errors from cropping up in the middle of things like "x = object.SubObject.SubSubObject.SoOn" by writing:<br /><br />var x = from obj in object<br />from so in obj.SubObject<br />from sso in so.SubSubObject<br />from soOn in sso.SoOn<br />select soOn;<br /><br />x will equal soOn if that whole chain exists, or it will equal null if any of those subobjects is null. Very handy.Daxhttps://www.blogger.com/profile/08009087262659272412noreply@blogger.com