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;
2using System.Collections.Generic;
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.GetTypeInfo().GetCustomAttributes<ModuleDependencyAttribute>();
23 IEnumerable<ModuleDependencyAttribute> AttrsY = TypeY.GetTypeInfo().GetCustomAttributes<ModuleDependencyAttribute>();
24 bool XDependsOnY = false;
25 bool YDependsOnX = false;
26
27 if (!(AttrsX is null))
28 {
29 foreach (ModuleDependencyAttribute AttrX in AttrsX)
30 {
31 if (AttrX.DependsOn(TypeY))
32 {
33 XDependsOnY = true;
34 break;
35 }
36 }
37 }
38
39 if (!(AttrsY is null))
40 {
41 foreach (ModuleDependencyAttribute AttrY in AttrsY)
42 {
43 if (AttrY.DependsOn(TypeX))
44 {
45 YDependsOnX = true;
46 break;
47 }
48 }
49 }
50
51 int i = XDependsOnY.CompareTo(YDependsOnX);
52 if (i != 0)
53 return i;
54 else
55 return TypeX.FullName.CompareTo(TypeY.FullName);
56 }
57 }
58}
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