Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visual studio offers to convert Expression-body in c# to block body for method : IDE0022 [closed]

public ActionResult Edit(int id)
        => Json(_itemMasterBL.GetItemMaster()?.Where(x => x.Id == id).FirstOrDefault(), JsonRequestBehavior.AllowGet);

I have the above piece of code as expression-bodied method (c# 6.0).

But in visual studio 2017 quick actions (ctrl + .) it makes this suggestion:

IDE0022: use block body for methods as follows:

public ActionResult Edit(int id)
    {
        return Json(_itemMasterBL.GetItemMaster()?.Where(x => x.Id == id).FirstOrDefault(), JsonRequestBehavior.AllowGet);
    }

What is the meaning of this suggestion? Is it proposing that this change should be preferred for some reason? Or is it just offering the possibility as a convenience?

like image 665
Abi Avatar asked Apr 17 '17 11:04

Abi


1 Answers

Converting between expression body and block body is somewhat tedious and something you might want to do fairly often. Which is why I think VS offers it as a refactoring, it isn't a statement of one being better than the other.

like image 109
svick Avatar answered Oct 20 '22 05:10

svick