From 5390ea994aa575d0b31abd2d577fc6a278c851c6 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 19 Mar 2022 11:11:58 -0700 Subject: Minor code clean up --- .../WindowsInstaller/TableDefinitionCollection.cs | 47 +++++++++++++++++----- src/wix/WixToolset.Core/Compiler_Tag.cs | 3 +- .../SymbolDefinitionCreator.cs | 32 +++++++-------- 3 files changed, 53 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/api/wix/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs b/src/api/wix/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs index fcc2b1f6..522e3b84 100644 --- a/src/api/wix/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs +++ b/src/api/wix/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs @@ -14,7 +14,7 @@ namespace WixToolset.Data.WindowsInstaller { public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wi/tables"; - private Dictionary collection; + private readonly Dictionary collection; /// /// Instantiate a new TableDefinitionCollection class. @@ -74,59 +74,86 @@ namespace WixToolset.Data.WindowsInstaller /// Name of table to locate. /// Table definition if found. /// True if table definition was found otherwise false. - public bool TryGet(string tableName, out TableDefinition table) => this.collection.TryGetValue(tableName, out table); + public bool TryGet(string tableName, out TableDefinition table) + { + return this.collection.TryGetValue(tableName, out table); + } /// /// Adds a table definition to the collection. /// /// Table definition to add to the collection. /// Indexes by table definition name. - public void Add(TableDefinition tableDefinition) => this.collection.Add(tableDefinition.Name, tableDefinition); + public void Add(TableDefinition tableDefinition) + { + this.collection.Add(tableDefinition.Name, tableDefinition); + } /// /// Removes all table definitions from the collection. /// - public void Clear() => this.collection.Clear(); + public void Clear() + { + this.collection.Clear(); + } /// /// Checks if the collection contains a table name. /// /// The table to check in the collection. /// True if collection contains the table. - public bool Contains(string tableName) => this.collection.ContainsKey(tableName); + public bool Contains(string tableName) + { + return this.collection.ContainsKey(tableName); + } /// /// Checks if the collection contains a table. /// /// The table to check in the collection. /// True if collection contains the table. - public bool Contains(TableDefinition table) => this.collection.ContainsKey(table.Name); + public bool Contains(TableDefinition table) + { + return this.collection.ContainsKey(table.Name); + } /// /// Copies table definitions to an arry. /// /// Array to copy the table definitions to. /// Index in the array to start copying at. - public void CopyTo(TableDefinition[] array, int index) => this.collection.Values.CopyTo(array, index); + public void CopyTo(TableDefinition[] array, int index) + { + this.collection.Values.CopyTo(array, index); + } /// /// Removes a table definition from the collection. /// /// Table to remove from the collection. /// True if the table definition existed in the collection and was removed. - public bool Remove(TableDefinition table) => this.collection.Remove(table.Name); + public bool Remove(TableDefinition table) + { + return this.collection.Remove(table.Name); + } /// /// Gets enumerator for the collection. /// /// Enumerator for the collection. - public IEnumerator GetEnumerator() => this.collection.Values.GetEnumerator(); + public IEnumerator GetEnumerator() + { + return this.collection.Values.GetEnumerator(); + } /// /// Gets the untyped enumerator for the collection. /// /// Untyped enumerator for the collection. - IEnumerator IEnumerable.GetEnumerator() => this.collection.Values.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + { + return this.collection.Values.GetEnumerator(); + } /// /// Loads a collection of table definitions from a XmlReader in memory. diff --git a/src/wix/WixToolset.Core/Compiler_Tag.cs b/src/wix/WixToolset.Core/Compiler_Tag.cs index 64341808..dfb14c5d 100644 --- a/src/wix/WixToolset.Core/Compiler_Tag.cs +++ b/src/wix/WixToolset.Core/Compiler_Tag.cs @@ -6,6 +6,7 @@ namespace WixToolset.Core using System.Xml.Linq; using WixToolset.Data; using WixToolset.Data.Symbols; + using WixToolset.Data.WindowsInstaller; /// /// Compiler of the WiX toolset. @@ -248,7 +249,7 @@ namespace WixToolset.Core } this.Core.CreateComplexReference(sourceLineNumbers, ComplexReferenceParentType.Feature, feature, null, ComplexReferenceChildType.Component, id.Id, true); - this.Core.EnsureTable(sourceLineNumbers, "SoftwareIdentificationTag"); + this.Core.EnsureTable(sourceLineNumbers, WindowsInstallerTableDefinitions.SoftwareIdentificationTag); this.Core.AddSymbol(new WixPackageTagSymbol(sourceLineNumbers, id) { FileRef = id.Id, diff --git a/src/wix/WixToolset.Core/ExtensibilityServices/SymbolDefinitionCreator.cs b/src/wix/WixToolset.Core/ExtensibilityServices/SymbolDefinitionCreator.cs index a2486130..651cd7e6 100644 --- a/src/wix/WixToolset.Core/ExtensibilityServices/SymbolDefinitionCreator.cs +++ b/src/wix/WixToolset.Core/ExtensibilityServices/SymbolDefinitionCreator.cs @@ -33,31 +33,27 @@ namespace WixToolset.Core.ExtensibilityServices { // First, look in the built-ins. symbolDefinition = SymbolDefinitions.ByName(name); - - if (symbolDefinition == null) + if (symbolDefinition != null) { - if (this.ExtensionData == null) - { - this.LoadExtensionData(); - } + return true; + } - // Second, look in the extensions. - foreach (var data in this.ExtensionData) - { - if (data.TryGetSymbolDefinitionByName(name, out symbolDefinition)) - { - break; - } - } + if (this.ExtensionData == null) + { + this.LoadExtensionData(); + } - // Finally, look in the custom symbol definitions provided during an intermediate load. - if (symbolDefinition == null) + // Second, look in the extensions. + foreach (var data in this.ExtensionData) + { + if (data.TryGetSymbolDefinitionByName(name, out symbolDefinition)) { - this.CustomDefinitionByName.TryGetValue(name, out symbolDefinition); + return true; } } - return symbolDefinition != null; + // Finally, look in the custom symbol definitions provided during an intermediate load. + return this.CustomDefinitionByName.TryGetValue(name, out symbolDefinition); } private void LoadExtensionData() -- cgit v1.2.3-55-g6feb