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