| 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.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="symbol">this</param> |
| 31 | /// <param name="other">Complex reference to compare to.</param> |
| 32 | /// <returns>Zero if the objects are equivalent, negative number if the provided object is less, positive if greater.</returns> |
| 33 | public static int CompareToWithoutConsideringPrimary(this WixComplexReferenceSymbol symbol, WixComplexReferenceSymbol other) |
| 34 | { |
| 35 | var comparison = symbol.ChildType - other.ChildType; |
| 36 | if (0 == comparison) |
| 37 | { |
| 38 | comparison = String.Compare(symbol.Child, other.Child, StringComparison.Ordinal); |
| 39 | if (0 == comparison) |
| 40 | { |
| 41 | comparison = symbol.ParentType - other.ParentType; |
| 42 | if (0 == comparison) |
| 43 | { |
| 44 | string thisParentLanguage = null == symbol.ParentLanguage ? String.Empty : symbol.ParentLanguage; |
| 45 | string otherParentLanguage = null == other.ParentLanguage ? String.Empty : other.ParentLanguage; |
| 46 | comparison = String.Compare(thisParentLanguage, otherParentLanguage, StringComparison.Ordinal); |
| 47 | if (0 == comparison) |
| 48 | { |
| 49 | comparison = String.Compare(symbol.Parent, other.Parent, StringComparison.Ordinal); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return comparison; |
| 56 | } |
| 57 | |
| 58 | /// <summary> |
| 59 | /// Changes all of the parent references to point to the passed in parent reference. |
| 60 | /// </summary> |
| 61 | /// <param name="symbol">this</param> |
| 62 | /// <param name="parent">New parent complex reference.</param> |
| 63 | public static void Reparent(this WixComplexReferenceSymbol symbol, WixComplexReferenceSymbol parent) |
| 64 | { |
| 65 | symbol.Parent = parent.Parent; |
| 66 | symbol.ParentLanguage = parent.ParentLanguage; |
| 67 | symbol.ParentType = parent.ParentType; |
| 68 | |
| 69 | if (!symbol.IsPrimary) |
| 70 | { |
| 71 | symbol.IsPrimary = parent.IsPrimary; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |