diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-08-20 14:22:07 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-08-20 14:25:49 -0700 |
| commit | 3e1c5e3fa80a2498f7d6aac5c0f8ca9e3bd7c66c (patch) | |
| tree | bbe907a4c5ebf7aa5e3f02141f6e3abd31cb7b5c /src/WixToolset.Extensibility/ExtensionHelper.cs | |
| parent | 6dee3b45cb679786bd49a5db8fde9006d283b3e2 (diff) | |
| download | wix-3e1c5e3fa80a2498f7d6aac5c0f8ca9e3bd7c66c.tar.gz wix-3e1c5e3fa80a2498f7d6aac5c0f8ca9e3bd7c66c.tar.bz2 wix-3e1c5e3fa80a2498f7d6aac5c0f8ca9e3bd7c66c.zip | |
Move to .NET Core 2.0
Diffstat (limited to 'src/WixToolset.Extensibility/ExtensionHelper.cs')
| -rw-r--r-- | src/WixToolset.Extensibility/ExtensionHelper.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/WixToolset.Extensibility/ExtensionHelper.cs b/src/WixToolset.Extensibility/ExtensionHelper.cs new file mode 100644 index 00000000..9c1ca950 --- /dev/null +++ b/src/WixToolset.Extensibility/ExtensionHelper.cs | |||
| @@ -0,0 +1,53 @@ | |||
| 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.Extensibility | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Specialized; | ||
| 7 | using System.IO; | ||
| 8 | using System.Reflection; | ||
| 9 | using System.Xml; | ||
| 10 | using WixToolset.Data; | ||
| 11 | using WixToolset.Extensibility; | ||
| 12 | |||
| 13 | /// <summary> | ||
| 14 | /// The main class for a WiX extension. | ||
| 15 | /// </summary> | ||
| 16 | public static class ExtensionHelper | ||
| 17 | { | ||
| 18 | /// <summary> | ||
| 19 | /// Help for loading a library from an embedded resource. | ||
| 20 | /// </summary> | ||
| 21 | /// <param name="assembly">The assembly containing the embedded resource.</param> | ||
| 22 | /// <param name="resourceName">The name of the embedded resource being requested.</param> | ||
| 23 | /// <param name="tableDefinitions">The table definitions to use while loading the library.</param> | ||
| 24 | /// <returns>The loaded library.</returns> | ||
| 25 | public static Library LoadLibraryHelper(Assembly assembly, string resourceName, TableDefinitionCollection tableDefinitions) | ||
| 26 | { | ||
| 27 | using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) | ||
| 28 | { | ||
| 29 | UriBuilder uriBuilder = new UriBuilder(); | ||
| 30 | uriBuilder.Scheme = "embeddedresource"; | ||
| 31 | uriBuilder.Path = assembly.Location; | ||
| 32 | uriBuilder.Fragment = resourceName; | ||
| 33 | |||
| 34 | return Library.Load(resourceStream, uriBuilder.Uri, tableDefinitions, false); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | /// <summary> | ||
| 39 | /// Helper for loading table definitions from an embedded resource. | ||
| 40 | /// </summary> | ||
| 41 | /// <param name="assembly">The assembly containing the embedded resource.</param> | ||
| 42 | /// <param name="resourceName">The name of the embedded resource being requested.</param> | ||
| 43 | /// <returns>The loaded table definitions.</returns> | ||
| 44 | public static TableDefinitionCollection LoadTableDefinitionHelper(Assembly assembly, string resourceName) | ||
| 45 | { | ||
| 46 | using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) | ||
| 47 | using (XmlReader reader = XmlReader.Create(resourceStream)) | ||
| 48 | { | ||
| 49 | return TableDefinitionCollection.Load(reader); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
