SharePoint: CSOM break folder permissions

Consider a scenario where you need to break permissions of a folder using client object model (CSOM) in SharePoint. The code below creates a folder in the document library, breaks its permissions and gives a particular user Contribute permissions on it. The main thing to note here is that, in CSOM Folder does not     have BreakRoleInheritance or Item method. It has a property named ListItemAllFields. This is used to break permissions as shown: 
using (var clientContext = new ClientContext("http://sitename"))
{                    
    Web web = clientContext.Web;
    List list = web.Lists.GetByTitle("Documents");
    Folder newFolder = list.RootFolder.Folders.Add("FolderName");
    clientContext.ExecuteQuery();    
    newFolder.ListItemAllFields.BreakRoleInheritance(false, true);
    var role = new RoleDefinitionBindingCollection(clientContext);
    role.Add(web.RoleDefinitions.GetByType(RoleType.Contributor));
    User user = web.EnsureUser("contoso\\adamb");
    newFolder.ListItemAllFields.RoleAssignments.Add(user, role);
    newFolder.Update();
    clientContext.ExecuteQuery();
}
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+