Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DependencyOrder.cs
1using System;
3using System.Reflection;
4
6{
10 public class DependencyOrder : IComparer<IModule>
11 {
18 public int Compare(IModule x, IModule y)
19 {
20 Type TypeX = x.GetType();
21 Type TypeY = y.GetType();
22 IEnumerable<ModuleDependencyAttribute> AttrsX = TypeX.GetCustomAttributes<ModuleDependencyAttribute>();
23 IEnumerable<ModuleDependencyAttribute> AttrsY = TypeY.GetCustomAttributes<ModuleDependencyAttribute>();
24 bool XHasDependencies = false;
25 bool YHasDependencies = false;
26 bool XDependsOnY = false;
27 bool YDependsOnX = false;
28
29 foreach (ModuleDependencyAttribute AttrX in AttrsX)
30 {
31 XHasDependencies = true;
32
33 if (AttrX.DependsOn(TypeY))
34 {
35 XDependsOnY = true;
36 break;
37 }
38 }
39
40 foreach (ModuleDependencyAttribute AttrY in AttrsY)
41 {
42 YHasDependencies = true;
43
44 if (AttrY.DependsOn(TypeX))
45 {
46 YDependsOnX = true;
47 break;
48 }
49 }
50
51 if (XHasDependencies)
52 {
53 if (!YHasDependencies)
54 return 1;
55 }
56 else if (YHasDependencies)
57 return -1;
58
59 int i = XDependsOnY.CompareTo(YDependsOnX);
60 if (i != 0)
61 return i;
62 else
63 return TypeX.FullName.CompareTo(TypeY.FullName);
64 }
65 }
66}
Orders modules in dependency order.
int Compare(IModule x, IModule y)
Compares two modules.
Defines a module dependency for a module class. Modules are started after a dependency,...
bool DependsOn(IModule Module)
Checks if there is a dependency on a given module.
Interface for late-bound modules loaded at runtime.
Definition: IModule.cs:9