diff --git a/src/Microsoft.AspNet.Razor/CSharpRazorCodeLanguage.cs b/src/Microsoft.AspNet.Razor/CSharpRazorCodeLanguage.cs index 834fad0a84..f90323a466 100644 --- a/src/Microsoft.AspNet.Razor/CSharpRazorCodeLanguage.cs +++ b/src/Microsoft.AspNet.Razor/CSharpRazorCodeLanguage.cs @@ -22,6 +22,8 @@ namespace Microsoft.AspNet.Razor get { return CSharpLanguageName; } } #if NET45 + // No CodeDOM in CoreCLR + /// /// Returns the type of the CodeDOM provider for this language /// diff --git a/src/Microsoft.AspNet.Razor/Editor/BackgroundParser.cs b/src/Microsoft.AspNet.Razor/Editor/BackgroundParser.cs index d50c381a53..2f59d12583 100644 --- a/src/Microsoft.AspNet.Razor/Editor/BackgroundParser.cs +++ b/src/Microsoft.AspNet.Razor/Editor/BackgroundParser.cs @@ -310,6 +310,11 @@ namespace Microsoft.AspNet.Razor.Editor { RazorEditorTrace.TraceLine(RazorResources.Trace_BackgroundThreadStart, fileNameOnly); EnsureOnThread(); + +#if K10 + var spinWait = new SpinWait(); +#endif + while (!_shutdownToken.IsCancellationRequested) { // Grab the parcel of work to do @@ -425,7 +430,12 @@ namespace Microsoft.AspNet.Razor.Editor { RazorEditorTrace.TraceLine(RazorResources.Trace_NoChangesArrived, fileNameOnly, parcel.Changes.Count); #if NET45 + // No Yield in CoreCLR + Thread.Yield(); +#else + // This does the equivalent of thread.yield under the covers. + spinWait.SpinOnce(); #endif } } diff --git a/src/Microsoft.AspNet.Razor/Editor/RazorEditorTrace.cs b/src/Microsoft.AspNet.Razor/Editor/RazorEditorTrace.cs index 2ce399b863..873d9a4bbb 100644 --- a/src/Microsoft.AspNet.Razor/Editor/RazorEditorTrace.cs +++ b/src/Microsoft.AspNet.Razor/Editor/RazorEditorTrace.cs @@ -25,6 +25,8 @@ namespace Microsoft.AspNet.Razor.Editor if (Boolean.TryParse(Environment.GetEnvironmentVariable("RAZOR_EDITOR_TRACE"), out enabled)) { #if NET45 + // No Trace in CoreCLR + Trace.WriteLine(String.Format( CultureInfo.CurrentCulture, RazorResources.Trace_Startup, @@ -46,6 +48,8 @@ namespace Microsoft.AspNet.Razor.Editor if (IsEnabled()) { #if NET45 + // No Trace in CoreCLR + Trace.WriteLine(String.Format( CultureInfo.CurrentCulture, RazorResources.Trace_Format, diff --git a/src/Microsoft.AspNet.Razor/Generator/AddImportCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/AddImportCodeGenerator.cs index 4c4701c00a..33864659e1 100644 --- a/src/Microsoft.AspNet.Razor/Generator/AddImportCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/AddImportCodeGenerator.cs @@ -36,6 +36,9 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateCode(Span target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM in CoreCLR. + // #if'd the entire section because once we transition over to the CodeTree we will not need all this code. + // Try to find the namespace in the existing imports string ns = Namespace; if (!String.IsNullOrEmpty(ns) && Char.IsWhiteSpace(ns[0])) diff --git a/src/Microsoft.AspNet.Razor/Generator/AttributeBlockCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/AttributeBlockCodeGenerator.cs index 60bd6249da..bc033f4e1d 100644 --- a/src/Microsoft.AspNet.Razor/Generator/AttributeBlockCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/AttributeBlockCodeGenerator.cs @@ -34,6 +34,9 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM in CoreCLR. + // #if'd the entire section because once we transition over to the CodeTree we will not need all this code. + if (context.Host.DesignTimeMode) { return; // Don't generate anything! @@ -72,6 +75,9 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM in CoreCLR (AddStatement and FlushBufferedStatement etc. utilize it). + // #if'd the entire section because once we transition over to the CodeTree we will not need all this code. + if (context.Host.DesignTimeMode) { return; // Don't generate anything! diff --git a/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs index b1b4458feb..7cabd12dae 100644 --- a/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/CSharpRazorCodeGenerator.cs @@ -25,6 +25,9 @@ namespace Microsoft.AspNet.Razor.Generator { base.Initialize(context); #if NET45 + // No CodeDOM in CoreCLR. + // #if'd the entire section because once we transition over to the CodeTree we will not need all this code. + context.GeneratedClass.Members.Insert(0, new CodeSnippetTypeMember(HiddenLinePragma)); #endif } diff --git a/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorContext.cs b/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorContext.cs index 7a65fbf036..491c82c284 100644 --- a/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorContext.cs +++ b/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorContext.cs @@ -32,6 +32,9 @@ namespace Microsoft.AspNet.Razor.Generator #region deletable #if NET45 + // This section is #if'd because it contains SOME incompatible pieces but also will not be needed once we transition over + // to using the CodeTree + private int _nextDesignTimePragmaId = 1; private bool _expressionHelperVariableWriten; private CodeMemberMethod _designTimeHelperMethod; @@ -318,6 +321,9 @@ namespace Microsoft.AspNet.Razor.Generator Host = host, SourceFile = shouldGenerateLinePragmas ? sourceFile : null, #if NET45 + // This section is #if'd because it contains SOME incompatible pieces but also will not be needed once we transition over + // to using the CodeTree + CodeWriterFactory = writerFactory, CompileUnit = new CodeCompileUnit(), Namespace = new CodeNamespace(rootNamespace), @@ -334,6 +340,8 @@ namespace Microsoft.AspNet.Razor.Generator #endif }; #if NET45 + // No CodeDOM in CoreCLR. + context.CompileUnit.Namespaces.Add(context.Namespace); context.Namespace.Types.Add(context.GeneratedClass); context.GeneratedClass.Members.Add(context.TargetMethod); diff --git a/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorPaddingHelper.cs b/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorPaddingHelper.cs index f689058b33..c8e21d3eb9 100644 --- a/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorPaddingHelper.cs +++ b/src/Microsoft.AspNet.Razor/Generator/CodeGeneratorPaddingHelper.cs @@ -10,6 +10,8 @@ using Microsoft.AspNet.Razor.Parser.SyntaxTree; namespace Microsoft.AspNet.Razor.Generator { #if NET45 + // This section is #if'd because it is no longer needed for the CodeTree transition. + internal static class CodeGeneratorPaddingHelper { private static readonly char[] _newLineChars = { '\r', '\n' }; diff --git a/src/Microsoft.AspNet.Razor/Generator/CodeWriter.cs b/src/Microsoft.AspNet.Razor/Generator/CodeWriter.cs index afd54fd9f2..1afbfef7b9 100644 --- a/src/Microsoft.AspNet.Razor/Generator/CodeWriter.cs +++ b/src/Microsoft.AspNet.Razor/Generator/CodeWriter.cs @@ -54,6 +54,8 @@ namespace Microsoft.AspNet.Razor.Generator public abstract void WriteStringLiteral(string literal); public abstract int WriteVariableDeclaration(string type, string name, string value); #if NET45 + // No CodeDOM in CoreCLR + public virtual void WriteLinePragma() { WriteLinePragma(null); @@ -169,6 +171,9 @@ namespace Microsoft.AspNet.Razor.Generator public virtual void WriteBooleanLiteral(bool value) { #if NET45 + // ToString does not take a parameter in CoreCLR + // #if'd the entire section because once we transition over to the CodeTree we will not need all this code. + WriteSnippet(value.ToString(CultureInfo.InvariantCulture)); #endif } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs index 8b1f98d2d6..4b85e62b12 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs @@ -29,9 +29,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp writer.WriteComment(new string('-', 78)) .WriteComment("") .WriteComment(" This code was generated by a tool.") -#if NET45 - .WriteComment(" Runtime Version: " + Assembly.GetExecutingAssembly().ImageRuntimeVersion) -#endif .WriteComment("") .WriteComment(" Changes to this file may cause incorrect behavior and will be lost if") .WriteComment(" the code is regenerated.") diff --git a/src/Microsoft.AspNet.Razor/Generator/DynamicAttributeBlockCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/DynamicAttributeBlockCodeGenerator.cs index 11966723ce..207b81f669 100644 --- a/src/Microsoft.AspNet.Razor/Generator/DynamicAttributeBlockCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/DynamicAttributeBlockCodeGenerator.cs @@ -41,6 +41,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // This code will not be needed once we transition to the CodeTree + if (context.Host.DesignTimeMode) { return; // Don't generate anything! @@ -55,6 +57,8 @@ namespace Microsoft.AspNet.Razor.Generator { _isExpression = true; #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + generatedCode = context.BuildCodeString(cw => { cw.WriteParameterSeparator(); @@ -68,6 +72,8 @@ namespace Microsoft.AspNet.Razor.Generator context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode; } #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + else { generatedCode = context.BuildCodeString(cw => @@ -108,6 +114,8 @@ namespace Microsoft.AspNet.Razor.Generator if (_isExpression) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + generatedCode = context.BuildCodeString(cw => { cw.WriteParameterSeparator(); @@ -123,6 +131,8 @@ namespace Microsoft.AspNet.Razor.Generator context.ExpressionRenderingMode = _oldRenderingMode; } #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + else { generatedCode = context.BuildCodeString(cw => diff --git a/src/Microsoft.AspNet.Razor/Generator/ExpressionCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/ExpressionCodeGenerator.cs index 109525c4bd..7dcc00499f 100644 --- a/src/Microsoft.AspNet.Razor/Generator/ExpressionCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/ExpressionCodeGenerator.cs @@ -18,6 +18,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + if (context.Host.EnableInstrumentation && context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput) { Span contentSpan = target.Children @@ -69,6 +71,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + string endBlock = context.BuildCodeString(cw => { if (context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput) @@ -115,6 +119,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateCode(Span target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + Span sourceSpan = null; if (context.CreateCodeWriter().SupportsMidStatementLinePragmas || context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput) { diff --git a/src/Microsoft.AspNet.Razor/Generator/HelperCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/HelperCodeGenerator.cs index 1dad54a760..2c96d82dbf 100644 --- a/src/Microsoft.AspNet.Razor/Generator/HelperCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/HelperCodeGenerator.cs @@ -40,6 +40,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + _writer = context.CreateCodeWriter(); string prefix = context.BuildCodeString( @@ -78,6 +80,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + _statementCollectorToken.Dispose(); if (HeaderComplete) { @@ -126,6 +130,8 @@ namespace Microsoft.AspNet.Razor.Generator } #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + private void AddStatementToHelper(string statement, CodeLinePragma pragma) { if (pragma != null) diff --git a/src/Microsoft.AspNet.Razor/Generator/LiteralAttributeCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/LiteralAttributeCodeGenerator.cs index a6437af8e0..6248b2f3c8 100644 --- a/src/Microsoft.AspNet.Razor/Generator/LiteralAttributeCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/LiteralAttributeCodeGenerator.cs @@ -45,6 +45,8 @@ namespace Microsoft.AspNet.Razor.Generator ExpressionRenderingMode oldMode = context.ExpressionRenderingMode; #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + context.BufferStatementFragment(context.BuildCodeString(cw => { cw.WriteParameterSeparator(); @@ -52,14 +54,17 @@ namespace Microsoft.AspNet.Razor.Generator cw.WriteLocationTaggedString(Prefix); cw.WriteParameterSeparator(); #endif - if (ValueGenerator != null) + if (ValueGenerator != null) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree cw.WriteStartMethodInvoke("Tuple.Create", "System.Object", "System.Int32"); #endif context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode; } #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + else { cw.WriteLocationTaggedString(Value); @@ -74,15 +79,21 @@ namespace Microsoft.AspNet.Razor.Generator { ValueGenerator.Value.GenerateCode(target, context); #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + context.FlushBufferedStatement(); #endif context.ExpressionRenderingMode = oldMode; #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + context.AddStatement(context.BuildCodeString(cw => { #endif - chunk.ValueLocation = ValueGenerator.Location; + chunk.ValueLocation = ValueGenerator.Location; #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + cw.WriteParameterSeparator(); cw.WriteSnippet(ValueGenerator.Location.AbsoluteIndex.ToString(CultureInfo.CurrentCulture)); cw.WriteEndMethodInvoke(); diff --git a/src/Microsoft.AspNet.Razor/Generator/MarkupCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/MarkupCodeGenerator.cs index 85ffc9225f..a2d5fc915e 100644 --- a/src/Microsoft.AspNet.Razor/Generator/MarkupCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/MarkupCodeGenerator.cs @@ -20,6 +20,8 @@ namespace Microsoft.AspNet.Razor.Generator return; } #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + if (context.Host.EnableInstrumentation) { context.AddContextCall(target, context.Host.GeneratedClassContext.BeginContextMethodName, isLiteral: true); diff --git a/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs index f121105a2f..4734e2cf89 100644 --- a/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/RazorCodeGenerator.cs @@ -77,6 +77,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void OnComplete() { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + Context.FlushBufferedStatement(); #endif } diff --git a/src/Microsoft.AspNet.Razor/Generator/RazorCommentCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/RazorCommentCodeGenerator.cs index bfe52af350..3600d14436 100644 --- a/src/Microsoft.AspNet.Razor/Generator/RazorCommentCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/RazorCommentCodeGenerator.cs @@ -10,6 +10,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + // Flush the buffered statement since we're interrupting it with a comment. if (!String.IsNullOrEmpty(context.CurrentBufferedStatement)) { diff --git a/src/Microsoft.AspNet.Razor/Generator/RazorDirectiveAttributeCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/RazorDirectiveAttributeCodeGenerator.cs index 6c1fdb4808..c09ebcbce2 100644 --- a/src/Microsoft.AspNet.Razor/Generator/RazorDirectiveAttributeCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/RazorDirectiveAttributeCodeGenerator.cs @@ -36,6 +36,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateCode(Span target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + var attributeType = new CodeTypeReference(typeof(RazorDirectiveAttribute)); var attributeDeclaration = new CodeAttributeDeclaration( attributeType, diff --git a/src/Microsoft.AspNet.Razor/Generator/ResolveUrlCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/ResolveUrlCodeGenerator.cs index 63ef77b85d..e98f3a0426 100644 --- a/src/Microsoft.AspNet.Razor/Generator/ResolveUrlCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/ResolveUrlCodeGenerator.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNet.Razor.Generator return; } #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + if (!context.Host.DesignTimeMode && String.IsNullOrEmpty(target.Content)) { return; diff --git a/src/Microsoft.AspNet.Razor/Generator/SectionCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/SectionCodeGenerator.cs index 3cfd902e9d..37794b79e3 100644 --- a/src/Microsoft.AspNet.Razor/Generator/SectionCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/SectionCodeGenerator.cs @@ -26,6 +26,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + string startBlock = context.BuildCodeString(cw => { cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.DefineSectionMethodName); @@ -48,6 +50,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + string startBlock = context.BuildCodeString(cw => { cw.WriteEndLambdaDelegate(); diff --git a/src/Microsoft.AspNet.Razor/Generator/SetBaseTypeCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/SetBaseTypeCodeGenerator.cs index a35607af65..22c366e898 100644 --- a/src/Microsoft.AspNet.Razor/Generator/SetBaseTypeCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/SetBaseTypeCodeGenerator.cs @@ -24,6 +24,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateCode(Span target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + context.GeneratedClass.BaseTypes.Clear(); context.GeneratedClass.BaseTypes.Add(new CodeTypeReference(ResolveType(context, BaseType.Trim()))); diff --git a/src/Microsoft.AspNet.Razor/Generator/SetLayoutCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/SetLayoutCodeGenerator.cs index d3e6b129d8..97df228c2f 100644 --- a/src/Microsoft.AspNet.Razor/Generator/SetLayoutCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/SetLayoutCodeGenerator.cs @@ -24,6 +24,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateCode(Span target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + if (!context.Host.DesignTimeMode && !String.IsNullOrEmpty(context.Host.GeneratedClassContext.LayoutPropertyName)) { context.TargetMethod.Statements.Add( diff --git a/src/Microsoft.AspNet.Razor/Generator/StatementCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/StatementCodeGenerator.cs index d4807a5e84..956cfb882a 100644 --- a/src/Microsoft.AspNet.Razor/Generator/StatementCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/StatementCodeGenerator.cs @@ -16,6 +16,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateCode(Span target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + context.FlushBufferedStatement(); string generatedCode = context.BuildCodeString(cw => diff --git a/src/Microsoft.AspNet.Razor/Generator/TemplateBlockCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/TemplateBlockCodeGenerator.cs index 1a1e511c2a..8aee5f7ba9 100644 --- a/src/Microsoft.AspNet.Razor/Generator/TemplateBlockCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/TemplateBlockCodeGenerator.cs @@ -20,6 +20,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + string generatedCode = context.BuildCodeString(cw => { cw.WriteStartLambdaExpression(ItemParameterName); @@ -47,6 +49,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + string generatedCode = context.BuildCodeString(cw => { cw.WriteEndLambdaDelegate(); diff --git a/src/Microsoft.AspNet.Razor/Generator/TypeMemberCodeGenerator.cs b/src/Microsoft.AspNet.Razor/Generator/TypeMemberCodeGenerator.cs index 422fb19c73..874d8f20b6 100644 --- a/src/Microsoft.AspNet.Razor/Generator/TypeMemberCodeGenerator.cs +++ b/src/Microsoft.AspNet.Razor/Generator/TypeMemberCodeGenerator.cs @@ -17,6 +17,8 @@ namespace Microsoft.AspNet.Razor.Generator public override void GenerateCode(Span target, CodeGeneratorContext context) { #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + string generatedCode = context.BuildCodeString(cw => { cw.WriteSnippet(target.Content); diff --git a/src/Microsoft.AspNet.Razor/GeneratorResults.cs b/src/Microsoft.AspNet.Razor/GeneratorResults.cs index e100105c89..531c4639e7 100644 --- a/src/Microsoft.AspNet.Razor/GeneratorResults.cs +++ b/src/Microsoft.AspNet.Razor/GeneratorResults.cs @@ -39,6 +39,8 @@ namespace Microsoft.AspNet.Razor public IList DesignTimeLineMappings { get; private set; } #if NET45 + // No CodeDOM + This code will not be needed once we transition to the CodeTree + public CodeCompileUnit CCU { get; set; } public IDictionary OLDDesignTimeLineMappings { get; set; } #endif diff --git a/src/Microsoft.AspNet.Razor/Parser/CSharpLanguageCharacteristics.cs b/src/Microsoft.AspNet.Razor/Parser/CSharpLanguageCharacteristics.cs index fdf5de0eed..c6dc393bb2 100644 --- a/src/Microsoft.AspNet.Razor/Parser/CSharpLanguageCharacteristics.cs +++ b/src/Microsoft.AspNet.Razor/Parser/CSharpLanguageCharacteristics.cs @@ -145,7 +145,10 @@ namespace Microsoft.AspNet.Razor.Parser return CSharpSymbolType.LessThan; default: #if NET45 - Debug.Fail("FlipBracket must be called with a bracket character"); + // No Debug.Fail + Debug.Fail("FlipBracket must be called with a bracket character"); +#else + Debug.Assert(false, "FlipBracket must be called with a bracket character"); #endif return CSharpSymbolType.Unknown; } diff --git a/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs b/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs index 3c3fd86226..077807840b 100644 --- a/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs +++ b/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs @@ -90,7 +90,11 @@ namespace Microsoft.AspNet.Razor.Parser return HtmlSymbolType.OpenAngle; default: #if NET45 - Debug.Fail("FlipBracket must be called with a bracket character"); + // No Debug.Fail in CoreCLR + + Debug.Fail("FlipBracket must be called with a bracket character"); +#else + Debug.Assert(false, "FlipBracket must be called with a bracket character"); #endif return HtmlSymbolType.Unknown; } diff --git a/src/Microsoft.AspNet.Razor/Parser/ParserContext.cs b/src/Microsoft.AspNet.Razor/Parser/ParserContext.cs index 66b4baf5a7..a027968cef 100644 --- a/src/Microsoft.AspNet.Razor/Parser/ParserContext.cs +++ b/src/Microsoft.AspNet.Razor/Parser/ParserContext.cs @@ -288,7 +288,11 @@ namespace Microsoft.AspNet.Razor.Parser if (_infiniteLoopGuardCount > InfiniteLoopCountThreshold) { #if NET45 + // No Debug.Fail in CoreCLR + Debug.Fail("An internal parser error is causing an infinite loop at this location."); +#else + Debug.Assert(false, "An internal parser error is causing an infinite loop at this location."); #endif _terminated = true; return true; diff --git a/src/Microsoft.AspNet.Razor/Parser/ParserHelpers.cs b/src/Microsoft.AspNet.Razor/Parser/ParserHelpers.cs index bdfd2014e8..417ea46e31 100644 --- a/src/Microsoft.AspNet.Razor/Parser/ParserHelpers.cs +++ b/src/Microsoft.AspNet.Razor/Parser/ParserHelpers.cs @@ -34,9 +34,11 @@ namespace Microsoft.AspNet.Razor.Parser value == '\t' || value == '\u000B' || // Vertical Tab #if NET45 + // No GetUnicodeCategory on Char in CoreCLR + Char.GetUnicodeCategory(value) == UnicodeCategory.SpaceSeparator; #else - Char.IsSeparator(value); + CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.SpaceSeparator; #endif } @@ -93,9 +95,11 @@ namespace Microsoft.AspNet.Razor.Parser public static bool IsDecimalDigit(char value) { #if NET45 + // No GetUnicodeCategory on Char in CoreCLR + return Char.GetUnicodeCategory(value) == UnicodeCategory.DecimalDigitNumber; #else - return Char.IsDigit(value); + return CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.DecimalDigitNumber; #endif } @@ -106,48 +110,57 @@ namespace Microsoft.AspNet.Razor.Parser public static bool IsLetter(char value) { + UnicodeCategory cat; #if NET45 - var cat = Char.GetUnicodeCategory(value); + // No GetUnicodeCategory on Char in CoreCLR + cat = Char.GetUnicodeCategory(value); +#else + cat = CharUnicodeInfo.GetUnicodeCategory(value); +#endif return cat == UnicodeCategory.UppercaseLetter || cat == UnicodeCategory.LowercaseLetter || cat == UnicodeCategory.TitlecaseLetter || cat == UnicodeCategory.ModifierLetter || cat == UnicodeCategory.OtherLetter || cat == UnicodeCategory.LetterNumber; -#else - return Char.IsLetter(value); -#endif - } public static bool IsFormatting(char value) { #if NET45 + // No GetUnicodeCategory on Char in CoreCLR + return Char.GetUnicodeCategory(value) == UnicodeCategory.Format; #else - return false; // TODO: Make the above work + + return CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.Format; #endif } public static bool IsCombining(char value) { + UnicodeCategory cat; #if NET45 - var cat = Char.GetUnicodeCategory(value); + // No GetUnicodeCategory on Char in CoreCLR + + cat = Char.GetUnicodeCategory(value); +#else + cat = CharUnicodeInfo.GetUnicodeCategory(value); +#endif return cat == UnicodeCategory.SpacingCombiningMark || cat == UnicodeCategory.NonSpacingMark; -#else - return false; // TODO: Make the above work -#endif - + } public static bool IsConnecting(char value) { #if NET45 + // No GetUnicodeCategory on Char in CoreCLR + return Char.GetUnicodeCategory(value) == UnicodeCategory.ConnectorPunctuation; #else - return false; // TODO: Make the above work + return CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.ConnectorPunctuation; #endif } diff --git a/src/Microsoft.AspNet.Razor/RazorCodeLanguage.cs b/src/Microsoft.AspNet.Razor/RazorCodeLanguage.cs index eb8101340c..a723301a0f 100644 --- a/src/Microsoft.AspNet.Razor/RazorCodeLanguage.cs +++ b/src/Microsoft.AspNet.Razor/RazorCodeLanguage.cs @@ -30,6 +30,8 @@ namespace Microsoft.AspNet.Razor /// public abstract string LanguageName { get; } #if NET45 + // No CodeDOM in CoreCLR + /// /// The type of the CodeDOM provider for this language /// diff --git a/src/Microsoft.AspNet.Razor/RazorDebugHelpers.cs b/src/Microsoft.AspNet.Razor/RazorDebugHelpers.cs index 08ccff7ef2..d703ac9226 100644 --- a/src/Microsoft.AspNet.Razor/RazorDebugHelpers.cs +++ b/src/Microsoft.AspNet.Razor/RazorDebugHelpers.cs @@ -40,6 +40,8 @@ namespace Microsoft.AspNet.Razor get { return _outputDebuggingEnabled; } } #if NET45 + // No CodeDOM in CoreCLR + [SuppressMessage("Microsoft.Security", "CA2141:TransparentMethodsMustNotSatisfyLinkDemandsFxCopRule", Justification = "This is debug only")] [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "This is debug only")] [SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.IO.StringWriter.#ctor", Justification = "This is debug only")] diff --git a/src/Microsoft.AspNet.Razor/RazorEngineHost.cs b/src/Microsoft.AspNet.Razor/RazorEngineHost.cs index fb3dbe6c61..c24bbeeed0 100644 --- a/src/Microsoft.AspNet.Razor/RazorEngineHost.cs +++ b/src/Microsoft.AspNet.Razor/RazorEngineHost.cs @@ -201,6 +201,8 @@ namespace Microsoft.AspNet.Razor return incomingCodeGenerator; } #if NET45 + // No CodeDOM in CoreCLR + /// /// Gets the important CodeDOM nodes generated by the code generator and has a chance to add to them. /// diff --git a/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs b/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs index 551025f061..e178de4984 100644 --- a/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs +++ b/src/Microsoft.AspNet.Razor/RazorTemplateEngine.cs @@ -167,6 +167,8 @@ namespace Microsoft.AspNet.Razor generator.DesignTimeMode = Host.DesignTimeMode; generator.Visit(results); #if NET45 + // No CodeDOM in CoreCLR, this calls into CodeDOM dependent code. + // Post process code Host.PostProcessGeneratedCode(generator.Context); #endif @@ -176,6 +178,8 @@ namespace Microsoft.AspNet.Razor if (Host.DesignTimeMode) { #if NET45 + // No CodeDOM in CoreCLR, this calls into CodeDOM dependent code. + designTimeLineMappings = generator.Context.CodeMappings; #endif } @@ -187,9 +191,12 @@ namespace Microsoft.AspNet.Razor return new GeneratorResults(results, builderResult) { #if NET45 + // No CodeDOM in CoreCLR, this calls into CodeDOM dependent code. + // Also this code will be removed once we transition into the CodeTree + CCU = generator.Context.CompileUnit, OLDDesignTimeLineMappings = designTimeLineMappings, -#endif +#endif CT = generator.Context.CodeTreeBuilder.CodeTree }; } diff --git a/src/Microsoft.AspNet.Razor/Text/SourceLocation.cs b/src/Microsoft.AspNet.Razor/Text/SourceLocation.cs index cdb213b201..273c0266eb 100644 --- a/src/Microsoft.AspNet.Razor/Text/SourceLocation.cs +++ b/src/Microsoft.AspNet.Razor/Text/SourceLocation.cs @@ -6,6 +6,7 @@ using System.Globalization; namespace Microsoft.AspNet.Razor.Text { #if NET45 + // No Serializable attribute in CoreCLR (no need for it anymore?) [Serializable] #endif public struct SourceLocation : IEquatable, IComparable diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/CSharpHelpers.cs b/src/Microsoft.AspNet.Razor/Tokenizer/CSharpHelpers.cs index 8c2c2e0971..52fb36dd1f 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/CSharpHelpers.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/CSharpHelpers.cs @@ -11,13 +11,14 @@ namespace Microsoft.AspNet.Razor.Tokenizer public static bool IsIdentifierStart(char character) { return Char.IsLetter(character) || - character == '_' + character == '_' || #if NET45 - || Char.GetUnicodeCategory(character) == UnicodeCategory.LetterNumber + // No GetUnicodeCategory on Char in CoreCLR + + Char.GetUnicodeCategory(character) == UnicodeCategory.LetterNumber; #else - || Char.IsLetterOrDigit(character) + CharUnicodeInfo.GetUnicodeCategory(character) == UnicodeCategory.LetterNumber; #endif - ; // Ln } public static bool IsIdentifierPart(char character) @@ -39,16 +40,19 @@ namespace Microsoft.AspNet.Razor.Tokenizer private static bool IsIdentifierPartByUnicodeCategory(char character) { + UnicodeCategory category; #if NET45 - UnicodeCategory category = Char.GetUnicodeCategory(character); - + // No GetUnicodeCategory on Char in CoreCLR + + category = Char.GetUnicodeCategory(character); +#else + category = CharUnicodeInfo.GetUnicodeCategory(character); +#endif + return category == UnicodeCategory.NonSpacingMark || // Mn category == UnicodeCategory.SpacingCombiningMark || // Mc category == UnicodeCategory.ConnectorPunctuation || // Pc category == UnicodeCategory.Format; // Cf -#else - return false; // TODO: Make the above work -#endif } } } diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs b/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs index 25ea2b3bb8..f5ba485ffa 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/HtmlTokenizer.cs @@ -153,7 +153,11 @@ namespace Microsoft.AspNet.Razor.Tokenizer return EndSymbol(HtmlSymbolType.DoubleHyphen); default: #if NET45 - Debug.Fail("Unexpected symbol!"); + // No Debug.Fail in CoreCLR + + Debug.Fail("Unexpected symbol!"); +#else + Debug.Assert(false, "Unexpected symbol"); #endif return EndSymbol(HtmlSymbolType.Unknown); } diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs b/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs index 64c9d05964..ea0fc1b031 100644 --- a/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs +++ b/src/Microsoft.AspNet.Razor/Tokenizer/Tokenizer.cs @@ -322,7 +322,11 @@ namespace Microsoft.AspNet.Razor.Tokenizer internal void AssertCurrent(char current) { #if NET45 + // No Debug.Assert with this many arguments in CoreCLR + Debug.Assert(CurrentCharacter == current, "CurrentCharacter Assumption violated", "Assumed that the current character would be {0}, but it is actually {1}", current, CurrentCharacter); +#else + Debug.Assert(CurrentCharacter == current, String.Format("CurrentCharacter Assumption violated. Assumed that the current character would be {0}, but it is actually {1}", current, CurrentCharacter)); #endif }