请各位大侠有空帮小弟看看问题到底是出在哪里,故障有两个,第一个是下面那个被调用的函数在return了以后还要在从SetParentNode(familyStr, entity.ParentCategoryId.Value)处按顺序往下执行一次(虽然并没有影响返回的结果);第二个是上面的主函数当中在return result以后,就说result是未被定义的变量,真的不知道是哪里出了问题了,希望各位大侠看看。。。

主函数

string SetFamilyNode(int parentCategoryId)
    {
        
try
        {
            
string result = parentCategoryId.ToString();

            
if (!parentCategoryId.Equals(0))
            {
                result 
= SetParentNode(new StringBuilder(result), parentCategoryId);
            }

            
return result;
        }
        
catch (Exception ex)
        {
            
throw new Exception(ex.Message.Trim());
        }
    }
被调用函数
string SetParentNode(StringBuilder familyStr, int infoCategoryId)
    {
        
try
        {
            entity 
= service.GetByInfoCategoryId(infoCategoryId);
            
if (entity != null)
            {
                familyStr.Append(
"," + entity.ParentCategoryId.Value.ToString());
                
if (!entity.ParentCategoryId.Value.Equals(0))
                {
                    SetParentNode(familyStr, entity.ParentCategoryId.Value);
                }
            }
            
return familyStr.ToString();
        }
        
catch (Exception ex)
        {
            
throw new Exception(ex.Message.Trim());
        }
    }
把上面的改成如下就可以了
string SetParentNode(StringBuilder familyStr, int infoCategoryId)
    {
        
try
        {
            InfoCategoryService service 
= new InfoCategoryService();
            InfoCategory entity 
= new InfoCategory();
            entity 
= service.GetByInfoCategoryId(infoCategoryId);
            
if (entity != null)
            {
                familyStr.Append(
"," + entity.ParentCategoryId.Value.ToString());
                
if (!entity.ParentCategoryId.Value.Equals(0))
                {
                    SetParentNode(familyStr, entity.ParentCategoryId.Value);
                }
            }
            
return familyStr.ToString();
        }
        
catch (Exception ex)
        {
            
throw new Exception(ex.Message.Trim());
        }
    }

相关文章:

  • 2021-06-30
  • 2021-11-14
  • 2021-09-26
  • 2022-03-08
  • 2021-11-12
  • 2021-06-30
  • 2022-12-23
猜你喜欢
  • 2021-09-01
  • 2021-11-21
  • 2021-10-07
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2021-02-18
相关资源
相似解决方案