diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-12-07 14:17:39 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-12-07 14:17:39 -0800 |
| commit | 221da62c05ef2b515eb507c77655514cd0ec32a4 (patch) | |
| tree | fabec5b8ac871f17de6fe0aad3e6188b9af42bfb /src/WixToolset.Data/WindowsInstaller/Rows/WixComplexReferenceRow.cs | |
| parent | ca376995792d2e2a1a7f39760989496702a8f603 (diff) | |
| download | wix-221da62c05ef2b515eb507c77655514cd0ec32a4.tar.gz wix-221da62c05ef2b515eb507c77655514cd0ec32a4.tar.bz2 wix-221da62c05ef2b515eb507c77655514cd0ec32a4.zip | |
Reintegrate MSI constructs into WxToolset.Data.WindowsInstaller namespace
Diffstat (limited to 'src/WixToolset.Data/WindowsInstaller/Rows/WixComplexReferenceRow.cs')
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/Rows/WixComplexReferenceRow.cs | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/src/WixToolset.Data/WindowsInstaller/Rows/WixComplexReferenceRow.cs b/src/WixToolset.Data/WindowsInstaller/Rows/WixComplexReferenceRow.cs new file mode 100644 index 00000000..2abd7656 --- /dev/null +++ b/src/WixToolset.Data/WindowsInstaller/Rows/WixComplexReferenceRow.cs | |||
| @@ -0,0 +1,202 @@ | |||
| 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.Data.WindowsInstaller.Rows | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Diagnostics.CodeAnalysis; | ||
| 7 | |||
| 8 | /// <summary> | ||
| 9 | /// Specialization of a row for the WixComplexReference table. | ||
| 10 | /// </summary> | ||
| 11 | public sealed class WixComplexReferenceRow : Row, IComparable | ||
| 12 | { | ||
| 13 | /// <summary> | ||
| 14 | /// Creates a WixComplexReferenceRow row that belongs to a table. | ||
| 15 | /// </summary> | ||
| 16 | /// <param name="sourceLineNumbers">Original source lines for this row.</param> | ||
| 17 | /// <param name="table">Table this row belongs to and should get its column definitions from.</param> | ||
| 18 | public WixComplexReferenceRow(SourceLineNumber sourceLineNumbers, Table table) | ||
| 19 | : base(sourceLineNumbers, table) | ||
| 20 | { | ||
| 21 | } | ||
| 22 | |||
| 23 | /// <summary> | ||
| 24 | /// Gets the parent type of the complex reference. | ||
| 25 | /// </summary> | ||
| 26 | /// <value>Parent type of the complex reference.</value> | ||
| 27 | public ComplexReferenceParentType ParentType | ||
| 28 | { | ||
| 29 | get { return (ComplexReferenceParentType)Enum.ToObject(typeof(ComplexReferenceParentType), (int)this.Fields[1].Data); } | ||
| 30 | set { this.Fields[1].Data = (int)value; } | ||
| 31 | } | ||
| 32 | |||
| 33 | /// <summary> | ||
| 34 | /// Gets or sets the parent identifier of the complex reference. | ||
| 35 | /// </summary> | ||
| 36 | /// <value>Parent identifier of the complex reference.</value> | ||
| 37 | public string ParentId | ||
| 38 | { | ||
| 39 | get { return (string)this.Fields[0].Data; } | ||
| 40 | set { this.Fields[0].Data = value; } | ||
| 41 | } | ||
| 42 | |||
| 43 | /// <summary> | ||
| 44 | /// Gets the parent language of the complex reference. | ||
| 45 | /// </summary> | ||
| 46 | /// <value>Parent language of the complex reference.</value> | ||
| 47 | public string ParentLanguage | ||
| 48 | { | ||
| 49 | get { return (string)this.Fields[2].Data; } | ||
| 50 | set { this.Fields[2].Data = value; } | ||
| 51 | } | ||
| 52 | |||
| 53 | /// <summary> | ||
| 54 | /// Gets the child type of the complex reference. | ||
| 55 | /// </summary> | ||
| 56 | /// <value>Child type of the complex reference.</value> | ||
| 57 | public ComplexReferenceChildType ChildType | ||
| 58 | { | ||
| 59 | get { return (ComplexReferenceChildType)Enum.ToObject(typeof(ComplexReferenceChildType), (int)this.Fields[4].Data); } | ||
| 60 | set { this.Fields[4].Data = (int)value; } | ||
| 61 | } | ||
| 62 | |||
| 63 | /// <summary> | ||
| 64 | /// Gets the child identifier of the complex reference. | ||
| 65 | /// </summary> | ||
| 66 | /// <value>Child identifier of the complex reference.</value> | ||
| 67 | public string ChildId | ||
| 68 | { | ||
| 69 | get { return (string)this.Fields[3].Data; } | ||
| 70 | set { this.Fields[3].Data = value; } | ||
| 71 | } | ||
| 72 | |||
| 73 | /// <summary> | ||
| 74 | /// Gets if this is the primary complex reference. | ||
| 75 | /// </summary> | ||
| 76 | /// <value>true if primary complex reference.</value> | ||
| 77 | public bool IsPrimary | ||
| 78 | { | ||
| 79 | get | ||
| 80 | { | ||
| 81 | return (0x1 == ((int)this.Fields[5].Data & 0x1)); | ||
| 82 | } | ||
| 83 | |||
| 84 | set | ||
| 85 | { | ||
| 86 | if (null == this.Fields[5].Data) | ||
| 87 | { | ||
| 88 | this.Fields[5].Data = 0; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (value) | ||
| 92 | { | ||
| 93 | this.Fields[5].Data = (int)this.Fields[5].Data | 0x1; | ||
| 94 | } | ||
| 95 | else | ||
| 96 | { | ||
| 97 | this.Fields[5].Data = (int)this.Fields[5].Data & ~0x1; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | /// <summary> | ||
| 103 | /// Determines if two complex references are equivalent. | ||
| 104 | /// </summary> | ||
| 105 | /// <param name="obj">Complex reference to compare.</param> | ||
| 106 | /// <returns>True if complex references are equivalent.</returns> | ||
| 107 | public override bool Equals(object obj) | ||
| 108 | { | ||
| 109 | return 0 == this.CompareTo(obj); | ||
| 110 | } | ||
| 111 | |||
| 112 | /// <summary> | ||
| 113 | /// Gets the hash code for the complex reference. | ||
| 114 | /// </summary> | ||
| 115 | /// <returns>Hash code for the complex reference.</returns> | ||
| 116 | public override int GetHashCode() | ||
| 117 | { | ||
| 118 | return this.ChildType.GetHashCode() ^ this.ChildId.GetHashCode() ^ this.ParentType.GetHashCode() ^ this.ParentLanguage.GetHashCode() ^ this.ParentId.GetHashCode() ^ this.IsPrimary.GetHashCode(); | ||
| 119 | } | ||
| 120 | |||
| 121 | /// <summary> | ||
| 122 | /// Compares two complex references. | ||
| 123 | /// </summary> | ||
| 124 | /// <param name="obj">Complex reference to compare to.</param> | ||
| 125 | /// <returns>Zero if the objects are equivalent, negative number if the provided object is less, positive if greater.</returns> | ||
| 126 | public int CompareTo(object obj) | ||
| 127 | { | ||
| 128 | int comparison = this.CompareToWithoutConsideringPrimary(obj); | ||
| 129 | if (0 == comparison) | ||
| 130 | { | ||
| 131 | comparison = ((WixComplexReferenceRow)obj).IsPrimary.CompareTo(this.IsPrimary); // Note: the order of these is purposely switched to ensure that "Yes" is lower than "No" and "NotSet" | ||
| 132 | } | ||
| 133 | return comparison; | ||
| 134 | } | ||
| 135 | |||
| 136 | /// <summary> | ||
| 137 | /// Compares two complex references without considering the primary bit. | ||
| 138 | /// </summary> | ||
| 139 | /// <param name="obj">Complex reference to compare to.</param> | ||
| 140 | /// <returns>Zero if the objects are equivalent, negative number if the provided object is less, positive if greater.</returns> | ||
| 141 | [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String,System.String)")] | ||
| 142 | public int CompareToWithoutConsideringPrimary(object obj) | ||
| 143 | { | ||
| 144 | var other = obj as WixComplexReferenceRow ?? throw new ArgumentNullException(nameof(obj)); | ||
| 145 | |||
| 146 | int comparison = this.ChildType - other.ChildType; | ||
| 147 | if (0 == comparison) | ||
| 148 | { | ||
| 149 | comparison = String.Compare(this.ChildId, other.ChildId, StringComparison.Ordinal); | ||
| 150 | if (0 == comparison) | ||
| 151 | { | ||
| 152 | comparison = this.ParentType - other.ParentType; | ||
| 153 | if (0 == comparison) | ||
| 154 | { | ||
| 155 | string thisParentLanguage = null == this.ParentLanguage ? String.Empty : this.ParentLanguage; | ||
| 156 | string otherParentLanguage = null == other.ParentLanguage ? String.Empty : other.ParentLanguage; | ||
| 157 | comparison = String.Compare(thisParentLanguage, otherParentLanguage, StringComparison.Ordinal); | ||
| 158 | if (0 == comparison) | ||
| 159 | { | ||
| 160 | comparison = String.Compare(this.ParentId, other.ParentId, StringComparison.Ordinal); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | return comparison; | ||
| 167 | } | ||
| 168 | |||
| 169 | /// <summary> | ||
| 170 | /// Creates a shallow copy of the ComplexReference. | ||
| 171 | /// </summary> | ||
| 172 | /// <returns>A shallow copy of the ComplexReference.</returns> | ||
| 173 | public WixComplexReferenceRow Clone() | ||
| 174 | { | ||
| 175 | WixComplexReferenceRow wixComplexReferenceRow = new WixComplexReferenceRow(this.SourceLineNumbers, this.Table); | ||
| 176 | wixComplexReferenceRow.ParentType = this.ParentType; | ||
| 177 | wixComplexReferenceRow.ParentId = this.ParentId; | ||
| 178 | wixComplexReferenceRow.ParentLanguage = this.ParentLanguage; | ||
| 179 | wixComplexReferenceRow.ChildType = this.ChildType; | ||
| 180 | wixComplexReferenceRow.ChildId = this.ChildId; | ||
| 181 | wixComplexReferenceRow.IsPrimary = this.IsPrimary; | ||
| 182 | |||
| 183 | return wixComplexReferenceRow; | ||
| 184 | } | ||
| 185 | |||
| 186 | /// <summary> | ||
| 187 | /// Changes all of the parent references to point to the passed in parent reference. | ||
| 188 | /// </summary> | ||
| 189 | /// <param name="parent">New parent complex reference.</param> | ||
| 190 | public void Reparent(WixComplexReferenceRow parent) | ||
| 191 | { | ||
| 192 | this.ParentId = parent.ParentId; | ||
| 193 | this.ParentLanguage = parent.ParentLanguage; | ||
| 194 | this.ParentType = parent.ParentType; | ||
| 195 | |||
| 196 | if (!this.IsPrimary) | ||
| 197 | { | ||
| 198 | this.IsPrimary = parent.IsPrimary; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | } | ||
| 202 | } | ||
