aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-06-25 14:47:54 -0700
committerRob Mensching <rob@firegiant.com>2020-06-25 14:50:31 -0700
commitfb2436ef2e5ba9b5c16c7f0fdc948fc6d1faf8b5 (patch)
tree6cd8ca9a9c5a459940c36b8b69b89977f0f5e7df /src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs
parent38afa9e7bc7eacc021f8805f607368a05751e3c3 (diff)
downloadwix-fb2436ef2e5ba9b5c16c7f0fdc948fc6d1faf8b5.tar.gz
wix-fb2436ef2e5ba9b5c16c7f0fdc948fc6d1faf8b5.tar.bz2
wix-fb2436ef2e5ba9b5c16c7f0fdc948fc6d1faf8b5.zip
The Great Tuple to Symbol File Rename (tm)
Diffstat (limited to 'src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs')
-rw-r--r--src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs b/src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs
new file mode 100644
index 00000000..1702d3ca
--- /dev/null
+++ b/src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.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.Symbols;
7
8 internal static class WixComplexReferenceSymbolExtensions
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 WixComplexReferenceSymbol Clone(this WixComplexReferenceSymbol source)
15 {
16 var clone = new WixComplexReferenceSymbol(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 WixComplexReferenceSymbol symbol, WixComplexReferenceSymbol other)
33 {
34 var comparison = symbol.ChildType - other.ChildType;
35 if (0 == comparison)
36 {
37 comparison = String.Compare(symbol.Child, other.Child, StringComparison.Ordinal);
38 if (0 == comparison)
39 {
40 comparison = symbol.ParentType - other.ParentType;
41 if (0 == comparison)
42 {
43 string thisParentLanguage = null == symbol.ParentLanguage ? String.Empty : symbol.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(symbol.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 WixComplexReferenceSymbol symbol, WixComplexReferenceSymbol parent)
62 {
63 symbol.Parent = parent.Parent;
64 symbol.ParentLanguage = parent.ParentLanguage;
65 symbol.ParentType = parent.ParentType;
66
67 if (!symbol.IsPrimary)
68 {
69 symbol.IsPrimary = parent.IsPrimary;
70 }
71 }
72 }
73}