Код: Выделить всё
public class Permissions
{
public string PermissionName { get; set; }
public List controllers { get; set; }
}
public class Controllers
{
public string ControllerName { get; set; }
public List actions { get; set; }
}
public class Actions
{
public string ActionName { get; set; }
public bool Active { get; set; }
}
Код: Выделить всё
var a1 = new Actions() { ActionName = "Action1", Active = false };
var a2 = new Actions() { ActionName = "Action2", Active = true };
var a3 = new Actions() { ActionName = "Action3", Active = true };
var a4 = new Actions() { ActionName = "Action4", Active = true };
var c1 = new Controllers() { ControllerName = "Controller1", actions = new List() { a1, a2 } };
var c2 = new Controllers() { ControllerName = "Controller2", actions = new List() { a3, a4 } };
var ListOfPermision = new List
()
{
new Permissions() { PermissionName = "P1", controllers = new List() { c1, c2 } }
};
//First Way:-------------------------------
ListOfPermision.ForEach(p =>
p.controllers.ForEach(c =>
c.actions.ForEach(a =>
{
if (!a.Active)
{
//Remove Controller
}
}
)));
//OR Second Way:----------------------------
foreach (var p in ListOfPermision)
{
foreach (var c in p.controllers)
{
foreach (var a in c.actions)
{
if (!a.Active)
{
//Remove Controller
}
}
}
}
//----------------------------------
Я не знаю, что мне лучше всего сделать. ..
Что делать, если я хочу удалить контроллер, счетчик действий которого равен 0?
Спасибо, ребята, за уделенное время
Подробнее здесь: https://stackoverflow.com/questions/786 ... de-foreach