|
5 | 5 | using System.Collections;
|
6 | 6 | using System.ComponentModel;
|
7 | 7 |
|
8 |
| -namespace PSRule.Rules.Azure.Configuration |
| 8 | +namespace PSRule.Rules.Azure.Configuration; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// Options that affect the properties of the <c>deployment()</c> object during expansion. |
| 12 | +/// </summary> |
| 13 | +public sealed class DeploymentOption : IEquatable<DeploymentOption> |
9 | 14 | {
|
| 15 | + private const string DEFAULT_NAME = "ps-rule-test-deployment"; |
| 16 | + |
| 17 | + internal static readonly DeploymentOption Default = new() |
| 18 | + { |
| 19 | + Name = DEFAULT_NAME |
| 20 | + }; |
| 21 | + |
10 | 22 | /// <summary>
|
11 |
| - /// Options that affect the properties of the <c>deployment()</c> object during expansion. |
| 23 | + /// Creates an empty deployment option. |
12 | 24 | /// </summary>
|
13 |
| - public sealed class DeploymentOption : IEquatable<DeploymentOption> |
| 25 | + public DeploymentOption() |
14 | 26 | {
|
15 |
| - private const string DEFAULT_NAME = "ps-rule-test-deployment"; |
| 27 | + Name = null; |
| 28 | + } |
16 | 29 |
|
17 |
| - internal static readonly DeploymentOption Default = new() |
18 |
| - { |
19 |
| - Name = DEFAULT_NAME |
20 |
| - }; |
| 30 | + internal DeploymentOption(DeploymentOption option) |
| 31 | + { |
| 32 | + if (option == null) |
| 33 | + return; |
21 | 34 |
|
22 |
| - /// <summary> |
23 |
| - /// Creates an empty deployment option. |
24 |
| - /// </summary> |
25 |
| - public DeploymentOption() |
26 |
| - { |
27 |
| - Name = null; |
28 |
| - } |
| 35 | + Name = option.Name; |
| 36 | + } |
29 | 37 |
|
30 |
| - internal DeploymentOption(DeploymentOption option) |
31 |
| - { |
32 |
| - if (option == null) |
33 |
| - return; |
| 38 | + internal DeploymentOption(string name) |
| 39 | + { |
| 40 | + Name = name ?? DEFAULT_NAME; |
| 41 | + } |
34 | 42 |
|
35 |
| - Name = option.Name; |
36 |
| - } |
| 43 | + /// <inheritdoc/> |
| 44 | + public override bool Equals(object obj) |
| 45 | + { |
| 46 | + return obj is DeploymentOption option && Equals(option); |
| 47 | + } |
37 | 48 |
|
38 |
| - internal DeploymentOption(string name) |
39 |
| - { |
40 |
| - Name = name ?? DEFAULT_NAME; |
41 |
| - } |
| 49 | + /// <inheritdoc/> |
| 50 | + public bool Equals(DeploymentOption other) |
| 51 | + { |
| 52 | + return other != null && |
| 53 | + Name == other.Name; |
| 54 | + } |
42 | 55 |
|
43 |
| - /// <inheritdoc/> |
44 |
| - public override bool Equals(object obj) |
45 |
| - { |
46 |
| - return obj is DeploymentOption option && Equals(option); |
47 |
| - } |
| 56 | + /// <summary> |
| 57 | + /// Compares two deployment options to determine if they are equal. |
| 58 | + /// </summary> |
| 59 | + public static bool operator ==(DeploymentOption o1, DeploymentOption o2) |
| 60 | + { |
| 61 | + return Equals(o1, o2); |
| 62 | + } |
48 | 63 |
|
49 |
| - /// <inheritdoc/> |
50 |
| - public bool Equals(DeploymentOption other) |
51 |
| - { |
52 |
| - return other != null && |
53 |
| - Name == other.Name; |
54 |
| - } |
| 64 | + /// <summary> |
| 65 | + /// Compares two deployment options to determine if they are not equal. |
| 66 | + /// </summary> |
| 67 | + public static bool operator !=(DeploymentOption o1, DeploymentOption o2) |
| 68 | + { |
| 69 | + return !Equals(o1, o2); |
| 70 | + } |
55 | 71 |
|
56 |
| - /// <summary> |
57 |
| - /// Compares two deployment options to determine if they are equal. |
58 |
| - /// </summary> |
59 |
| - public static bool operator ==(DeploymentOption o1, DeploymentOption o2) |
60 |
| - { |
61 |
| - return Equals(o1, o2); |
62 |
| - } |
| 72 | + /// <summary> |
| 73 | + /// Compares two deployment options to determine if they are equal. |
| 74 | + /// </summary> |
| 75 | + public static bool Equals(DeploymentOption o1, DeploymentOption o2) |
| 76 | + { |
| 77 | + return (object.Equals(null, o1) && object.Equals(null, o2)) || |
| 78 | + (!object.Equals(null, o1) && o1.Equals(o2)); |
| 79 | + } |
63 | 80 |
|
64 |
| - /// <summary> |
65 |
| - /// Compares two deployment options to determine if they are not equal. |
66 |
| - /// </summary> |
67 |
| - public static bool operator !=(DeploymentOption o1, DeploymentOption o2) |
| 81 | + /// <inheritdoc/> |
| 82 | + public override int GetHashCode() |
| 83 | + { |
| 84 | + unchecked // Overflow is fine |
68 | 85 | {
|
69 |
| - return !Equals(o1, o2); |
| 86 | + var hash = 17; |
| 87 | + hash = hash * 23 + (Name != null ? Name.GetHashCode() : 0); |
| 88 | + return hash; |
70 | 89 | }
|
| 90 | + } |
71 | 91 |
|
72 |
| - /// <summary> |
73 |
| - /// Compares two deployment options to determine if they are equal. |
74 |
| - /// </summary> |
75 |
| - public static bool Equals(DeploymentOption o1, DeploymentOption o2) |
| 92 | + internal static DeploymentOption Combine(DeploymentOption o1, DeploymentOption o2) |
| 93 | + { |
| 94 | + var result = new DeploymentOption() |
76 | 95 | {
|
77 |
| - return (object.Equals(null, o1) && object.Equals(null, o2)) || |
78 |
| - (!object.Equals(null, o1) && o1.Equals(o2)); |
79 |
| - } |
| 96 | + Name = o1?.Name ?? o2?.Name, |
| 97 | + }; |
| 98 | + return result; |
| 99 | + } |
80 | 100 |
|
81 |
| - /// <inheritdoc/> |
82 |
| - public override int GetHashCode() |
83 |
| - { |
84 |
| - unchecked // Overflow is fine |
85 |
| - { |
86 |
| - var hash = 17; |
87 |
| - hash = hash * 23 + (Name != null ? Name.GetHashCode() : 0); |
88 |
| - return hash; |
89 |
| - } |
90 |
| - } |
| 101 | + /// <summary> |
| 102 | + /// The name of the deployment. |
| 103 | + /// </summary> |
| 104 | + [DefaultValue(null)] |
| 105 | + public string Name { get; set; } |
91 | 106 |
|
92 |
| - internal static DeploymentOption Combine(DeploymentOption o1, DeploymentOption o2) |
| 107 | + internal static DeploymentOption FromHashtable(Hashtable hashtable) |
| 108 | + { |
| 109 | + var option = new DeploymentOption(); |
| 110 | + if (hashtable != null) |
93 | 111 | {
|
94 |
| - var result = new DeploymentOption() |
95 |
| - { |
96 |
| - Name = o1?.Name ?? o2?.Name, |
97 |
| - }; |
98 |
| - return result; |
| 112 | + var index = PSRuleOption.BuildIndex(hashtable); |
| 113 | + if (index.TryPopValue("Name", out string s)) |
| 114 | + option.Name = s; |
99 | 115 | }
|
| 116 | + return option; |
| 117 | + } |
| 118 | +} |
100 | 119 |
|
101 |
| - /// <summary> |
102 |
| - /// The name of the deployment. |
103 |
| - /// </summary> |
104 |
| - [DefaultValue(null)] |
105 |
| - public string Name { get; set; } |
| 120 | +/// <summary> |
| 121 | +/// A reference to a deployment. |
| 122 | +/// </summary> |
| 123 | +public sealed class DeploymentReference |
| 124 | +{ |
| 125 | + private DeploymentReference() { } |
106 | 126 |
|
107 |
| - internal static DeploymentOption FromHashtable(Hashtable hashtable) |
108 |
| - { |
109 |
| - var option = new DeploymentOption(); |
110 |
| - if (hashtable != null) |
111 |
| - { |
112 |
| - var index = PSRuleOption.BuildIndex(hashtable); |
113 |
| - if (index.TryPopValue("Name", out string s)) |
114 |
| - option.Name = s; |
115 |
| - } |
116 |
| - return option; |
117 |
| - } |
| 127 | + private DeploymentReference(string name) |
| 128 | + { |
| 129 | + Name = name; |
| 130 | + FromName = true; |
118 | 131 | }
|
119 | 132 |
|
120 | 133 | /// <summary>
|
121 |
| - /// A reference to a deployment. |
| 134 | + /// The name of the deployment. |
122 | 135 | /// </summary>
|
123 |
| - public sealed class DeploymentReference |
124 |
| - { |
125 |
| - private DeploymentReference() { } |
| 136 | + public string Name { get; set; } |
126 | 137 |
|
127 |
| - private DeploymentReference(string name) |
128 |
| - { |
129 |
| - Name = name; |
130 |
| - FromName = true; |
131 |
| - } |
132 |
| - |
133 |
| - /// <summary> |
134 |
| - /// The name of the deployment. |
135 |
| - /// </summary> |
136 |
| - public string Name { get; set; } |
137 |
| - |
138 |
| - /// <summary> |
139 |
| - /// Determines if the reference is created from a display name. |
140 |
| - /// </summary> |
141 |
| - public bool FromName { get; private set; } |
| 138 | + /// <summary> |
| 139 | + /// Determines if the reference is created from a display name. |
| 140 | + /// </summary> |
| 141 | + public bool FromName { get; private set; } |
142 | 142 |
|
143 |
| - /// <summary> |
144 |
| - /// Create a deployment reference from a hashtable. |
145 |
| - /// </summary> |
146 |
| - public static implicit operator DeploymentReference(Hashtable hashtable) |
147 |
| - { |
148 |
| - return FromHashtable(hashtable); |
149 |
| - } |
| 143 | + /// <summary> |
| 144 | + /// Create a deployment reference from a hashtable. |
| 145 | + /// </summary> |
| 146 | + public static implicit operator DeploymentReference(Hashtable hashtable) |
| 147 | + { |
| 148 | + return FromHashtable(hashtable); |
| 149 | + } |
150 | 150 |
|
151 |
| - /// <summary> |
152 |
| - /// Create a deployment reference from a name. |
153 |
| - /// </summary> |
154 |
| - public static implicit operator DeploymentReference(string deploymentName) |
155 |
| - { |
156 |
| - return FromString(deploymentName); |
157 |
| - } |
| 151 | + /// <summary> |
| 152 | + /// Create a deployment reference from a name. |
| 153 | + /// </summary> |
| 154 | + public static implicit operator DeploymentReference(string deploymentName) |
| 155 | + { |
| 156 | + return FromString(deploymentName); |
| 157 | + } |
158 | 158 |
|
159 |
| - /// <summary> |
160 |
| - /// Create a deployment reference from a hashtable. |
161 |
| - /// </summary> |
162 |
| - public static DeploymentReference FromHashtable(Hashtable hashtable) |
| 159 | + /// <summary> |
| 160 | + /// Create a deployment reference from a hashtable. |
| 161 | + /// </summary> |
| 162 | + public static DeploymentReference FromHashtable(Hashtable hashtable) |
| 163 | + { |
| 164 | + var option = new DeploymentReference(); |
| 165 | + if (hashtable != null) |
163 | 166 | {
|
164 |
| - var option = new DeploymentReference(); |
165 |
| - if (hashtable != null) |
166 |
| - { |
167 |
| - var index = PSRuleOption.BuildIndex(hashtable); |
168 |
| - if (index.TryPopValue("Name", out string s)) |
169 |
| - option.Name = s; |
170 |
| - } |
171 |
| - return option; |
| 167 | + var index = PSRuleOption.BuildIndex(hashtable); |
| 168 | + if (index.TryPopValue("Name", out string s)) |
| 169 | + option.Name = s; |
172 | 170 | }
|
| 171 | + return option; |
| 172 | + } |
173 | 173 |
|
174 |
| - /// <summary> |
175 |
| - /// Create a deployment reference from a name. |
176 |
| - /// </summary> |
177 |
| - public static DeploymentReference FromString(string deploymentName) |
178 |
| - { |
179 |
| - return new DeploymentReference(deploymentName); |
180 |
| - } |
| 174 | + /// <summary> |
| 175 | + /// Create a deployment reference from a name. |
| 176 | + /// </summary> |
| 177 | + public static DeploymentReference FromString(string deploymentName) |
| 178 | + { |
| 179 | + return new DeploymentReference(deploymentName); |
| 180 | + } |
181 | 181 |
|
182 |
| - /// <summary> |
183 |
| - /// Convert the reference to an option. |
184 |
| - /// </summary> |
185 |
| - public DeploymentOption ToDeploymentOption() |
186 |
| - { |
187 |
| - return new DeploymentOption(Name); |
188 |
| - } |
| 182 | + /// <summary> |
| 183 | + /// Convert the reference to an option. |
| 184 | + /// </summary> |
| 185 | + public DeploymentOption ToDeploymentOption() |
| 186 | + { |
| 187 | + return new DeploymentOption(Name); |
189 | 188 | }
|
190 | 189 | }
|
0 commit comments