From fb2436ef2e5ba9b5c16c7f0fdc948fc6d1faf8b5 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 25 Jun 2020 14:47:54 -0700 Subject: The Great Tuple to Symbol File Rename (tm) --- .../Link/WixComplexReferenceSymbolExtensions.cs | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs (limited to 'src/WixToolset.Core/Link/WixComplexReferenceSymbolExtensions.cs') 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 @@ +// 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. + +namespace WixToolset.Core.Link +{ + using System; + using WixToolset.Data.Symbols; + + internal static class WixComplexReferenceSymbolExtensions + { + /// + /// Creates a shallow copy of the ComplexReference. + /// + /// A shallow copy of the ComplexReference. + public static WixComplexReferenceSymbol Clone(this WixComplexReferenceSymbol source) + { + var clone = new WixComplexReferenceSymbol(source.SourceLineNumbers, source.Id); + clone.ParentType = source.ParentType; + clone.Parent = source.Parent; + clone.ParentLanguage = source.ParentLanguage; + clone.ChildType = source.ChildType; + clone.Child = source.Child; + clone.IsPrimary = source.IsPrimary; + + return clone; + } + + /// + /// Compares two complex references without considering the primary bit. + /// + /// Complex reference to compare to. + /// Zero if the objects are equivalent, negative number if the provided object is less, positive if greater. + public static int CompareToWithoutConsideringPrimary(this WixComplexReferenceSymbol symbol, WixComplexReferenceSymbol other) + { + var comparison = symbol.ChildType - other.ChildType; + if (0 == comparison) + { + comparison = String.Compare(symbol.Child, other.Child, StringComparison.Ordinal); + if (0 == comparison) + { + comparison = symbol.ParentType - other.ParentType; + if (0 == comparison) + { + string thisParentLanguage = null == symbol.ParentLanguage ? String.Empty : symbol.ParentLanguage; + string otherParentLanguage = null == other.ParentLanguage ? String.Empty : other.ParentLanguage; + comparison = String.Compare(thisParentLanguage, otherParentLanguage, StringComparison.Ordinal); + if (0 == comparison) + { + comparison = String.Compare(symbol.Parent, other.Parent, StringComparison.Ordinal); + } + } + } + } + + return comparison; + } + + /// + /// Changes all of the parent references to point to the passed in parent reference. + /// + /// New parent complex reference. + public static void Reparent(this WixComplexReferenceSymbol symbol, WixComplexReferenceSymbol parent) + { + symbol.Parent = parent.Parent; + symbol.ParentLanguage = parent.ParentLanguage; + symbol.ParentType = parent.ParentType; + + if (!symbol.IsPrimary) + { + symbol.IsPrimary = parent.IsPrimary; + } + } + } +} -- cgit v1.2.3-55-g6feb