Incorrect SA1119 warning?

May 29, 2012 at 9:19 PM

I know it's ugly, but I can't seem to figure out why this is telling me there are unnecessary parens on the right side of the :.. 

 

var newsItem = newsItemId > 0
	? entities.ArbitraryItems.Single(p => p.ArbitraryItemId == newsItemId)
	: ((Func<ArbitraryItem>)(() =>
		{
			var newItem = new ArbitraryItem();
			entities.ArbitraryItems.Add(newItem);
			return newItem;
		}))();

Coordinator
May 30, 2012 at 9:22 AM

Ca none of the opening parenthesis be removed in either the '((Func' or perhaps the ')(() =' ?

May 30, 2012 at 10:16 AM
Edited May 30, 2012 at 10:19 AM

Removing any set of parens from that code results in a compilation error. Here's a simplified version. 

var number = ((Func<int>)(() => 5))();

Coordinator
May 30, 2012 at 10:25 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.