From 3e0360a8915d457abd19534adb2fe8f6581f589e Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Wed, 28 Feb 2018 13:21:04 -0800 Subject: [PATCH] Fix #2041 - Add static constructor to DocumentWriter The instance Create method was always supposed to be static. (cherry picked from commit e05c2abd949d6a9acdfb82ae17594031582ca06f) --- .../CodeGeneration/DocumentWriter.cs | 18 ++++++++++++++++++ .../DefaultRazorCSharpLoweringPhase.cs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DocumentWriter.cs b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DocumentWriter.cs index fcfa014da2..68f7ddffc0 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DocumentWriter.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DocumentWriter.cs @@ -2,12 +2,30 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.ComponentModel; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration { public abstract class DocumentWriter { + public static DocumentWriter CreateDefault(CodeTarget codeTarget, RazorCodeGenerationOptions options) + { + if (codeTarget == null) + { + throw new ArgumentNullException(nameof(codeTarget)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + return new DefaultDocumentWriter(codeTarget, options); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This method was intended to be static, use CreateDefault instead.")] public DocumentWriter Create(CodeTarget codeTarget, RazorCodeGenerationOptions options) { if (codeTarget == null) diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs index 4f9ff9f151..f09c68069a 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.Language throw new InvalidOperationException(message); } - var writer = new DefaultDocumentWriter(documentNode.Target, documentNode.Options); + var writer = DocumentWriter.CreateDefault(documentNode.Target, documentNode.Options); var cSharpDocument = writer.WriteDocument(codeDocument, documentNode); codeDocument.SetCSharpDocument(cSharpDocument); }