diff options
Diffstat (limited to 'src/WixToolset.Core.Burn/Bind/ProvidesDependencyCollection.cs')
-rw-r--r-- | src/WixToolset.Core.Burn/Bind/ProvidesDependencyCollection.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/WixToolset.Core.Burn/Bind/ProvidesDependencyCollection.cs b/src/WixToolset.Core.Burn/Bind/ProvidesDependencyCollection.cs new file mode 100644 index 00000000..668b81d3 --- /dev/null +++ b/src/WixToolset.Core.Burn/Bind/ProvidesDependencyCollection.cs | |||
@@ -0,0 +1,64 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.Core.Burn | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.ObjectModel; | ||
7 | |||
8 | /// <summary> | ||
9 | /// A case-insensitive collection of unique <see cref="ProvidesDependency"/> objects. | ||
10 | /// </summary> | ||
11 | internal sealed class ProvidesDependencyCollection : KeyedCollection<string, ProvidesDependency> | ||
12 | { | ||
13 | /// <summary> | ||
14 | /// Creates a case-insensitive collection of unique <see cref="ProvidesDependency"/> objects. | ||
15 | /// </summary> | ||
16 | internal ProvidesDependencyCollection() | ||
17 | : base(StringComparer.InvariantCultureIgnoreCase) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | /// <summary> | ||
22 | /// Adds the <see cref="ProvidesDependency"/> to the collection if it doesn't already exist. | ||
23 | /// </summary> | ||
24 | /// <param name="dependency">The <see cref="ProvidesDependency"/> to add to the collection.</param> | ||
25 | /// <returns>True if the <see cref="ProvidesDependency"/> was added to the collection; otherwise, false.</returns> | ||
26 | /// <exception cref="ArgumentNullException">The <paramref name="dependency"/> parameter is null.</exception> | ||
27 | internal bool Merge(ProvidesDependency dependency) | ||
28 | { | ||
29 | if (null == dependency) | ||
30 | { | ||
31 | throw new ArgumentNullException("dependency"); | ||
32 | } | ||
33 | |||
34 | // If the dependency key is already in the collection, verify equality for a subset of properties. | ||
35 | if (this.Contains(dependency.Key)) | ||
36 | { | ||
37 | ProvidesDependency current = this[dependency.Key]; | ||
38 | if (!current.Equals(dependency)) | ||
39 | { | ||
40 | return false; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | base.Add(dependency); | ||
45 | return true; | ||
46 | } | ||
47 | |||
48 | /// <summary> | ||
49 | /// Gets the <see cref="ProvidesDependency.Key"/> for the <paramref name="dependency"/>. | ||
50 | /// </summary> | ||
51 | /// <param name="dependency">The dependency to index.</param> | ||
52 | /// <exception cref="ArgumentNullException">The <paramref name="dependency"/> parameter is null.</exception> | ||
53 | /// <returns>The <see cref="ProvidesDependency.Key"/> for the <paramref name="dependency"/>.</returns> | ||
54 | protected override string GetKeyForItem(ProvidesDependency dependency) | ||
55 | { | ||
56 | if (null == dependency) | ||
57 | { | ||
58 | throw new ArgumentNullException("dependency"); | ||
59 | } | ||
60 | |||
61 | return dependency.Key; | ||
62 | } | ||
63 | } | ||
64 | } | ||