// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.Dnx.Runtime;
namespace Microsoft.AspNet.Mvc.Razor.Precompilation
{
///
/// Specifies metadata about precompiled views.
///
public abstract class RazorFileInfoCollection
{
///
/// Gets or sets the name of the resource containing the precompiled binary.
///
public string AssemblyResourceName { get; protected set; }
///
/// Gets or sets the name of the resource that contains the symbols (pdb).
///
public string SymbolsResourceName { get; protected set; }
///
/// Gets the of s.
///
public IReadOnlyList FileInfos { get; protected set; }
///
/// Loads the assembly containing precompiled views.
///
/// The .
/// The containing precompiled views.
public virtual Assembly LoadAssembly(IAssemblyLoadContext loadContext)
{
var viewCollectionAssembly = GetType().GetTypeInfo().Assembly;
using (var assemblyStream = viewCollectionAssembly.GetManifestResourceStream(AssemblyResourceName))
{
if (assemblyStream == null)
{
var message = Resources.FormatRazorFileInfoCollection_ResourceCouldNotBeFound(AssemblyResourceName,
GetType().FullName);
throw new InvalidOperationException(message);
}
Stream symbolsStream = null;
if (!string.IsNullOrEmpty(SymbolsResourceName))
{
symbolsStream = viewCollectionAssembly.GetManifestResourceStream(SymbolsResourceName);
}
using (symbolsStream)
{
return loadContext.LoadStream(assemblyStream, symbolsStream);
}
}
}
}
}