Merge branch 'rel/vs15.7' into dev

This commit is contained in:
Ryan Nowak 2018-02-19 14:06:34 -08:00
commit c032988ddf
5 changed files with 79 additions and 23 deletions

View File

@ -27,5 +27,29 @@ namespace Microsoft.AspNetCore.Razor.Language
public override string ExtensionName { get; }
public Assembly Assembly { get; }
public RazorExtensionInitializer CreateInitializer()
{
// It's not an error to have an assembly with no initializers. This is useful to specify a dependency
// that doesn't really provide any Razor configuration.
var attributes = Assembly.GetCustomAttributes<ProvideRazorExtensionInitializerAttribute>();
foreach (var attribute in attributes)
{
// Using extension names and requiring them to line up allows a single assembly to ship multiple
// extensions/initializers for different configurations.
if (!string.Equals(attribute.ExtensionName, ExtensionName, StringComparison.Ordinal))
{
continue;
}
// There's no real protection/exception handling here because this set isn't really user-extensible
// right now. This would be a great place to add some additional diagnostics and hardening in the
// future.
var initializer = (RazorExtensionInitializer)Activator.CreateInstance(attribute.InitializerType);
return initializer;
}
return null;
}
}
}

View File

@ -159,29 +159,8 @@ namespace Microsoft.AspNetCore.Razor.Language
// lid on how things work until we add official support for extensibility everywhere. So, this is
// intentionally inflexible for the time being.
var extension = extensions[i] as AssemblyExtension;
if (extension == null)
{
continue;
}
// It's not an error to have an assembly with no initializers. This is useful to specify a dependency
// that doesn't really provide any Razor configuration.
var attributes = extension.Assembly.GetCustomAttributes<ProvideRazorExtensionInitializerAttribute>();
foreach (var attribute in attributes)
{
// Using extension names and requiring them to line up allows a single assembly to ship multiple
// extensions/initializers for different configurations.
if (!string.Equals(attribute.ExtensionName, extension.ExtensionName, StringComparison.Ordinal))
{
continue;
}
// There's no real protection/exception handling here because this set isn't really user-extensible
// right now. This would be a great place to add some additional diagnostics and hardening in the
// future.
var initializer = (RazorExtensionInitializer)Activator.CreateInstance(attribute.InitializerType);
initializer.Initialize(builder);
}
var initializer = extension?.CreateInitializer();
initializer?.Initialize(builder);
}
}
}

View File

@ -0,0 +1,28 @@
// 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.Composition;
namespace Microsoft.CodeAnalysis.Razor
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class ExportCustomProjectEngineFactoryAttribute : ExportAttribute, ICustomProjectEngineFactoryMetadata
{
public ExportCustomProjectEngineFactoryAttribute(string configurationName)
: base(typeof(IProjectEngineFactory))
{
if (configurationName == null)
{
throw new ArgumentNullException(nameof(configurationName));
}
ConfigurationName = configurationName;
}
public string ConfigurationName { get; }
public bool SupportsSerialization { get; set; }
}
}

View File

@ -0,0 +1,12 @@
// 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.
namespace Microsoft.CodeAnalysis.Razor
{
public interface ICustomProjectEngineFactoryMetadata
{
string ConfigurationName { get; }
bool SupportsSerialization { get; }
}
}

View File

@ -0,0 +1,13 @@
// 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 Microsoft.AspNetCore.Razor.Language;
namespace Microsoft.CodeAnalysis.Razor
{
public interface IProjectEngineFactory
{
RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem, Action<RazorProjectEngineBuilder> configure);
}
}