aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Link/WixComplexReferenceTupleExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Link/WixComplexReferenceTupleExtensions.cs')
-rw-r--r--src/WixToolset.Core/Link/WixComplexReferenceTupleExtensions.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Link/WixComplexReferenceTupleExtensions.cs b/src/WixToolset.Core/Link/WixComplexReferenceTupleExtensions.cs
new file mode 100644
index 00000000..80cafa50
--- /dev/null
+++ b/src/WixToolset.Core/Link/WixComplexReferenceTupleExtensions.cs
@@ -0,0 +1,73 @@
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
3namespace WixToolset.Core.Link
4{
5 using System;
6 using WixToolset.Data.Tuples;
7
8 internal static class WixComplexReferenceTupleExtensions
9 {
10 /// <summary>
11 /// Creates a shallow copy of the ComplexReference.
12 /// </summary>
13 /// <returns>A shallow copy of the ComplexReference.</returns>
14 public static WixComplexReferenceTuple Clone(this WixComplexReferenceTuple source)
15 {
16 var clone = new WixComplexReferenceTuple(source.SourceLineNumbers, source.Id);
17 clone.ParentType = source.ParentType;
18 clone.Parent = source.Parent;
19 clone.ParentLanguage = source.ParentLanguage;
20 clone.ChildType = source.ChildType;
21 clone.Child = source.Child;
22 clone.IsPrimary = source.IsPrimary;
23
24 return clone;
25 }
26
27 /// <summary>
28 /// Compares two complex references without considering the primary bit.
29 /// </summary>
30 /// <param name="obj">Complex reference to compare to.</param>
31 /// <returns>Zero if the objects are equivalent, negative number if the provided object is less, positive if greater.</returns>
32 public static int CompareToWithoutConsideringPrimary(this WixComplexReferenceTuple tuple, WixComplexReferenceTuple other)
33 {
34 var comparison = tuple.ChildType - other.ChildType;
35 if (0 == comparison)
36 {
37 comparison = String.Compare(tuple.Child, other.Child, StringComparison.Ordinal);
38 if (0 == comparison)
39 {
40 comparison = tuple.ParentType - other.ParentType;
41 if (0 == comparison)
42 {
43 string thisParentLanguage = null == tuple.ParentLanguage ? String.Empty : tuple.ParentLanguage;
44 string otherParentLanguage = null == other.ParentLanguage ? String.Empty : other.ParentLanguage;
45 comparison = String.Compare(thisParentLanguage, otherParentLanguage, StringComparison.Ordinal);
46 if (0 == comparison)
47 {
48 comparison = String.Compare(tuple.Parent, other.Parent, StringComparison.Ordinal);
49 }
50 }
51 }
52 }
53
54 return comparison;
55 }
56
57 /// <summary>
58 /// Changes all of the parent references to point to the passed in parent reference.
59 /// </summary>
60 /// <param name="parent">New parent complex reference.</param>
61 public static void Reparent(this WixComplexReferenceTuple tuple, WixComplexReferenceTuple parent)
62 {
63 tuple.Parent = parent.Parent;
64 tuple.ParentLanguage = parent.ParentLanguage;
65 tuple.ParentType = parent.ParentType;
66
67 if (!tuple.IsPrimary)
68 {
69 tuple.IsPrimary = parent.IsPrimary;
70 }
71 }
72 }
73}