Addressed Taylors feedback
This commit is contained in:
parent
82579b6333
commit
0c6ec09958
|
|
@ -54,48 +54,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
public override IReadOnlyList<IRazorProjectEngineFeature> ProjectFeatures { get; }
|
public override IReadOnlyList<IRazorProjectEngineFeature> ProjectFeatures { get; }
|
||||||
|
|
||||||
protected override void ConfigureParserOptions(RazorParserOptionsBuilder builder)
|
protected override RazorCodeDocument CreateCodeDocumentCore(RazorProjectItem projectItem)
|
||||||
{
|
|
||||||
if (builder == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(builder));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ConfigureDesignTimeParserOptions(RazorParserOptionsBuilder builder)
|
|
||||||
{
|
|
||||||
if (builder == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(builder));
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.SetDesignTime(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ConfigureCodeGenerationOptions(RazorCodeGenerationOptionsBuilder builder)
|
|
||||||
{
|
|
||||||
if (builder == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(builder));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ConfigureDesignTimeCodeGenerationOptions(RazorCodeGenerationOptionsBuilder builder)
|
|
||||||
{
|
|
||||||
if (builder == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(builder));
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.SetDesignTime(true);
|
|
||||||
builder.SuppressChecksum = true;
|
|
||||||
builder.SuppressMetadataAttributes = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override RazorCodeDocument ProcessCore(
|
|
||||||
RazorProjectItem projectItem,
|
|
||||||
Action<RazorParserOptionsBuilder> configureParser,
|
|
||||||
Action<RazorCodeGenerationOptionsBuilder> configureCodeGeneration)
|
|
||||||
{
|
{
|
||||||
if (projectItem == null)
|
if (projectItem == null)
|
||||||
{
|
{
|
||||||
|
|
@ -107,14 +66,38 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var importFeature = GetRequiredFeature<IImportProjectFeature>();
|
var importFeature = GetRequiredFeature<IImportProjectFeature>();
|
||||||
var imports = importFeature.GetImports(projectItem);
|
var imports = importFeature.GetImports(projectItem);
|
||||||
|
|
||||||
var parserOptions = GetRequiredFeature<IRazorParserOptionsFactoryProjectFeature>().Create(configureParser);
|
var parserOptions = GetRequiredFeature<IRazorParserOptionsFactoryProjectFeature>().Create(ConfigureParserOptions);
|
||||||
var codeGenerationOptions = GetRequiredFeature<IRazorCodeGenerationOptionsFactoryProjectFeature>().Create(configureCodeGeneration);
|
var codeGenerationOptions = GetRequiredFeature<IRazorCodeGenerationOptionsFactoryProjectFeature>().Create(ConfigureCodeGenerationOptions);
|
||||||
|
|
||||||
var codeDocument = RazorCodeDocument.Create(sourceDocument, imports, parserOptions, codeGenerationOptions);
|
return RazorCodeDocument.Create(sourceDocument, imports, parserOptions, codeGenerationOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override RazorCodeDocument CreateCodeDocumentDesignTimeCore(RazorProjectItem projectItem)
|
||||||
|
{
|
||||||
|
if (projectItem == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(projectItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);
|
||||||
|
|
||||||
|
var importFeature = GetRequiredFeature<IImportProjectFeature>();
|
||||||
|
var imports = importFeature.GetImports(projectItem);
|
||||||
|
|
||||||
|
var parserOptions = GetRequiredFeature<IRazorParserOptionsFactoryProjectFeature>().Create(ConfigureDesignTimeParserOptions);
|
||||||
|
var codeGenerationOptions = GetRequiredFeature<IRazorCodeGenerationOptionsFactoryProjectFeature>().Create(ConfigureDesignTimeCodeGenerationOptions);
|
||||||
|
|
||||||
|
return RazorCodeDocument.Create(sourceDocument, imports, parserOptions, codeGenerationOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ProcessCore(RazorCodeDocument codeDocument)
|
||||||
|
{
|
||||||
|
if (codeDocument == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(codeDocument));
|
||||||
|
}
|
||||||
|
|
||||||
Engine.Process(codeDocument);
|
Engine.Process(codeDocument);
|
||||||
|
|
||||||
return codeDocument;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TFeature GetRequiredFeature<TFeature>() where TFeature : IRazorProjectEngineFeature
|
private TFeature GetRequiredFeature<TFeature>() where TFeature : IRazorProjectEngineFeature
|
||||||
|
|
@ -130,5 +113,25 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
return feature;
|
return feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ConfigureParserOptions(RazorParserOptionsBuilder builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureDesignTimeParserOptions(RazorParserOptionsBuilder builder)
|
||||||
|
{
|
||||||
|
builder.SetDesignTime(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureCodeGenerationOptions(RazorCodeGenerationOptionsBuilder builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureDesignTimeCodeGenerationOptions(RazorCodeGenerationOptionsBuilder builder)
|
||||||
|
{
|
||||||
|
builder.SetDesignTime(true);
|
||||||
|
builder.SuppressChecksum = true;
|
||||||
|
builder.SuppressMetadataAttributes = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,6 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
|
|
||||||
public abstract IReadOnlyList<IRazorProjectEngineFeature> ProjectFeatures { get; }
|
public abstract IReadOnlyList<IRazorProjectEngineFeature> ProjectFeatures { get; }
|
||||||
|
|
||||||
protected abstract void ConfigureParserOptions(RazorParserOptionsBuilder builder);
|
|
||||||
|
|
||||||
protected abstract void ConfigureDesignTimeParserOptions(RazorParserOptionsBuilder builder);
|
|
||||||
|
|
||||||
protected abstract void ConfigureCodeGenerationOptions(RazorCodeGenerationOptionsBuilder builder);
|
|
||||||
|
|
||||||
protected abstract void ConfigureDesignTimeCodeGenerationOptions(RazorCodeGenerationOptionsBuilder builder);
|
|
||||||
|
|
||||||
public virtual RazorCodeDocument Process(RazorProjectItem projectItem)
|
public virtual RazorCodeDocument Process(RazorProjectItem projectItem)
|
||||||
{
|
{
|
||||||
if (projectItem == null)
|
if (projectItem == null)
|
||||||
|
|
@ -37,7 +29,9 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
throw new ArgumentNullException(nameof(projectItem));
|
throw new ArgumentNullException(nameof(projectItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProcessCore(projectItem, ConfigureParserOptions, ConfigureCodeGenerationOptions);
|
var codeDocument = CreateCodeDocumentCore(projectItem);
|
||||||
|
ProcessCore(codeDocument);
|
||||||
|
return codeDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual RazorCodeDocument ProcessDesignTime(RazorProjectItem projectItem)
|
public virtual RazorCodeDocument ProcessDesignTime(RazorProjectItem projectItem)
|
||||||
|
|
@ -47,13 +41,16 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
throw new ArgumentNullException(nameof(projectItem));
|
throw new ArgumentNullException(nameof(projectItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProcessCore(projectItem, ConfigureDesignTimeParserOptions, ConfigureDesignTimeCodeGenerationOptions);
|
var codeDocument = CreateCodeDocumentDesignTimeCore(projectItem);
|
||||||
|
ProcessCore(codeDocument);
|
||||||
|
return codeDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract RazorCodeDocument ProcessCore(
|
protected abstract RazorCodeDocument CreateCodeDocumentCore(RazorProjectItem projectItem);
|
||||||
RazorProjectItem projectItem,
|
|
||||||
Action<RazorParserOptionsBuilder> configureParser,
|
protected abstract RazorCodeDocument CreateCodeDocumentDesignTimeCore(RazorProjectItem projectItem);
|
||||||
Action<RazorCodeGenerationOptionsBuilder> configureCodeGeneration);
|
|
||||||
|
protected abstract void ProcessCore(RazorCodeDocument codeDocument);
|
||||||
|
|
||||||
public static RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem) => Create(configuration, fileSystem, configure: null);
|
public static RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem) => Create(configuration, fileSystem, configure: null);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue