C# 循环依赖,分片,聚类

2022/4/19 12:12:32

本文主要是介绍C# 循环依赖,分片,聚类,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 1   public static List<ProjectModel> While_ProjectRef(ProjectModel projectModel,SolutionModel solutionModel,
 2             List<ProjectModel> ProjectCrip)
 3         {
 4             List<ProjectModel> Self_Refs = new List<ProjectModel>();
 5             if(projectModel.Projectrefs.Count>0)
 6             {
 7                 foreach(var ProjectRef in projectModel.Projectrefs)
 8                 {
 9                     //对于每一个项目引用进行分析
10                     foreach (var project in solutionModel.Projects)
11                     {
12                         //寻找项目引用的projecta
13                         if (project.Name == ProjectRef.Name)
14                         {
15                             //如果已经被分析过了,那么就不再分析这个子引用
16                             if (ProjectCrip.Contains(project))
17                                 break;
18                             ProjectCrip.Add(project);
19                             Self_Refs.Add(project);
20                             break;
21                         }
22                     }
23                 }
24                 foreach (var Project_ref in Self_Refs)
25                 {
26                     var child_project_ref=While_ProjectRef(Project_ref, solutionModel, ProjectCrip);
27                     ProjectCrip = ProjectCrip.Union(child_project_ref).ToList();
28                 }
29             }
30             return ProjectCrip;
31         }
32 
33 
34  static public void Main(string[] args)
35         {
36             SolutionModel solutionModel = new SolutionModel();
37             ProjectModel A1 = new ProjectModel();
38             A1.Name = "A1";
39             ProjectModel A2 = new ProjectModel();
40             A2.Name = "A2";
41             ProjectModel A3 = new ProjectModel();
42             A3.Name = "A3";
43             //Model1: A1-》A2-》A3
44             //A1.Projectrefs.Add(A2);
45             //A2.Projectrefs.Add(A3);
46             //Model2: A1-》A2-》A1
47             //A1.Projectrefs.Add(A2);
48             //A2.Projectrefs.Add(A1);
49             //Model3: A1-》A2-》A3->A1
50             //A1.Projectrefs.Add(A2);
51             //A2.Projectrefs.Add(A3);
52             //A2.Projectrefs.Add(A1);
53 
54             //Model4: A1-》A2-》A3->A1
55             //        A1->A3->A1
56             //A1.Projectrefs.Add(A2);
57             //A2.Projectrefs.Add(A3);
58             //A3.Projectrefs.Add(A1);
59 
60             //A1.Projectrefs.Add(A3);
61             //A3.Projectrefs.Add(A1);
62             //Model5: A1-》A1
63             A1.Projectrefs.Add(A1);
64 
65 
66             solutionModel.Projects.Add(A1);
67             solutionModel.Projects.Add(A2);
68             solutionModel.Projects.Add(A3);
69 
70             List<ProjectModel> result=new List<ProjectModel> ();
71             result = While_ProjectRef(A1, solutionModel, result);
72             if(!result.Contains(A1))
73                 result.Add(A1);
74             Console.ReadKey();
75         }

 



这篇关于C# 循环依赖,分片,聚类的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程