// 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.
namespace WixToolset.Extensibility
{
using System;
using System.IO;
using System.Reflection;
using System.Xml;
using WixToolset.Data;
public abstract class ExtensionData : IExtensionData
{
///
/// Gets the optional table definitions for this extension.
///
/// Table definisions for this extension or null if there are no table definitions.
public virtual TableDefinitionCollection TableDefinitions
{
get { return null; }
}
///
/// Gets the optional default culture.
///
/// The optional default culture.
public virtual string DefaultCulture
{
get { return null; }
}
///
/// Gets the optional library associated with this extension.
///
/// The table definitions to use while loading the library.
/// The library for this extension or null if there is no library.
public virtual Library GetLibrary(TableDefinitionCollection tableDefinitions)
{
return null;
}
///
/// Help for loading a library from an embedded resource.
///
/// The assembly containing the embedded resource.
/// The name of the embedded resource being requested.
/// The table definitions to use while loading the library.
/// The loaded library.
protected static Library LoadLibraryHelper(Assembly assembly, string resourceName, TableDefinitionCollection tableDefinitions)
{
using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
{
UriBuilder uriBuilder = new UriBuilder(assembly.CodeBase);
uriBuilder.Scheme = "embeddedresource";
uriBuilder.Fragment = resourceName;
return Library.Load(resourceStream, uriBuilder.Uri, tableDefinitions, false);
}
}
///
/// Helper for loading table definitions from an embedded resource.
///
/// The assembly containing the embedded resource.
/// The name of the embedded resource being requested.
/// The loaded table definitions.
protected static TableDefinitionCollection LoadTableDefinitionHelper(Assembly assembly, string resourceName)
{
using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
using (XmlReader reader = XmlReader.Create(resourceStream))
{
return TableDefinitionCollection.Load(reader);
}
}
}
}