Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SingletonKey.cs
1using System;
2using System.Text;
3
5{
9 public class SingletonKey
10 {
11 private readonly Type type;
12 private readonly object[] arguments;
13
19 public SingletonKey(Type Type, object[] Arguments)
20 {
21 this.type = Type;
22 this.arguments = Arguments;
23 }
24
28 public Type Type => this.type;
29
33 public object[] Arguments => this.arguments;
34
36 public override bool Equals(object obj)
37 {
38 int i, c;
39
40 if (!(obj is SingletonKey Key) ||
41 this.type != Key.type ||
42 (this.arguments is null) ^ (Key.arguments is null) ||
43 (c = this.arguments?.Length ?? 0) != (Key.arguments?.Length ?? 0))
44 {
45 return false;
46 }
47
48 for (i = 0; i < c; i++)
49 {
50 if (!this.arguments[i].Equals(Key.arguments[i]))
51 return false;
52 }
53
54 return true;
55 }
56
58 public override int GetHashCode()
59 {
60 int Result = this.type.GetHashCode();
61
62 if (!(this.arguments is null))
63 {
64 foreach (object Obj in this.arguments)
65 Result ^= Result << 5 ^ (Obj?.GetHashCode() ?? 0);
66 }
67
68 return Result;
69 }
70
72 public override string ToString()
73 {
74 StringBuilder sb = new StringBuilder();
75 int i, c;
76
77 sb.Append(this.type.FullName);
78 sb.Append('(');
79
80 for (i = 0, c = this.arguments?.Length ?? 0; i < c; i++)
81 {
82 if (i > 0)
83 sb.Append(", ");
84
85 if (this.arguments[i] is null)
86 sb.Append("null");
87 else
88 sb.Append(this.arguments[i].GetType().FullName);
89 }
90
91 sb.Append(')');
92
93 return sb.ToString();
94 }
95 }
96}
Represents a type and a set of arguments, for which an object instance is the single instantiation.
Definition: SingletonKey.cs:10
SingletonKey(Type Type, object[] Arguments)
Represents a type and a set of arguments, for which an object instance is the single instantiation.
Definition: SingletonKey.cs:19
object[] Arguments
Arguments, for which the instance is unique.
Definition: SingletonKey.cs:33
override bool Equals(object obj)
Definition: SingletonKey.cs:36