Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果子级存在,则树层次结构设置标志true#_C#_Treeview_Parent Child_Hierarchy - Fatal编程技术网

C# 如果子级存在,则树层次结构设置标志true#

C# 如果子级存在,则树层次结构设置标志true#,c#,treeview,parent-child,hierarchy,C#,Treeview,Parent Child,Hierarchy,我正在尝试将issetting标志设置为true,如果存在一个 家长 //类文件 公共类EopsModule { 公共int ID{get;set;} 公共字符串模块代码{get;set;} 公共字符串说明{get;set;} 公共bool IsDefaultModule{get;set;} public int?ParentID{get;set;} 公共bool设置{get;set;} 公共列表子项{get;set;} } 公共IResponseResult GetApplicationSet

我正在尝试将issetting标志设置为true,如果存在一个 家长

//类文件
公共类EopsModule
{
公共int ID{get;set;}
公共字符串模块代码{get;set;}
公共字符串说明{get;set;}
公共bool IsDefaultModule{get;set;}
public int?ParentID{get;set;}
公共bool设置{get;set;}
公共列表子项{get;set;}
}
公共IResponseResult GetApplicationSettingWithModule()
{
IResponseResult responseResult=新的responseResult();
动态=新的ExpandooObject();
尝试
{
var settingsDetails=_databaseManager.getmultipleDataBabyJSON(DatabaseStoredProcedures.spGetAllApplicationSetting.ToString()).Result;
var oObjectDeserializeObject=Newtonsoft.Json.JsonConvert.DeserializeObject(设置详细信息);
//在这里获取列表中的所有EOPSMODEL
var moduleTreeHierarchy=\u eopsModuleManager.GetAllEopsModuleWithHierarchy().Result;
dynamic.settingsDetails=oObjectDeserializeObject;
dynamic.moduleTreeHierarchy=moduleTreeHierarchy;
string=string.Empty;
foreach(oObjectDeserializeObject中的变量项)
{
oModuleCode=item.moduleCode;
moduleTreeHierarchy。
其中(x=>x.ModuleCode==oModuleCode).ToList().ForEach(x=>
{
x、 IsSetting=true;
});
}
responseResult=Helper.Response.ResponseModel(动态,true,Helper.Constants.apisucture,HttpStatusCode.OK,true);
}
捕获(例外)
{
responseResult=Helper.Response.ResponseModel(null、false、Helper.Constants.ApiFailure、HttpStatusCode.BadRequest、true);
}
返回响应结果;
}
我正在迭代的循环适用于父级,但它不更新子值的值, 想知道它是否可以通过递归函数实现

请查找包含现有代码的输出:


你试过这样的东西吗?我没有通过编译器,但你会明白的

public UpdateModuleAndChildren(Module moduleTreeHierarchy) {
    if(moduleTreeHierarchy.children != null && moduleTreeHierarchy.children.Count() > 0) {
          moduleTreeHierarchy.children.forEach(x => { this.UpdateModuleAndChildren(x) });
          module.IsSetting = true;
    }
} 
如果有帮助,请告诉我


在代码中,您只需调用this.UpdateModuleAndChildren(moduleTreeHierarchy)

尝试设置
dynamic.moduleTreeHierarchy=moduleTreeHierarchy就在
ForEach循环的下方
经过一些调整后,我能够让它工作,谢谢你,这节省了我的时间。太棒了!很高兴我能帮忙。别忘了投票/接受有用的答案
public UpdateModuleAndChildren(Module moduleTreeHierarchy) {
    if(moduleTreeHierarchy.children != null && moduleTreeHierarchy.children.Count() > 0) {
          moduleTreeHierarchy.children.forEach(x => { this.UpdateModuleAndChildren(x) });
          module.IsSetting = true;
    }
}