Code Cleanup
Use var Conditional can be simplified Redundant array creation expression Parameter name differs in base declaration Empty statement is redundant
This commit is contained in:
parent
2ab54e73c5
commit
b03d3aa56f
|
|
@ -45,9 +45,9 @@ namespace Microsoft.AspNetCore.Razor
|
||||||
return new RazorChunkGenerator(className, rootNamespaceName, sourceFileName, host);
|
return new RazorChunkGenerator(className, rootNamespaceName, sourceFileName, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override CodeGenerator CreateCodeGenerator(CodeGeneratorContext context)
|
public override CodeGenerator CreateCodeGenerator(CodeGeneratorContext chunkGeneratorContext)
|
||||||
{
|
{
|
||||||
return new CSharpCodeGenerator(context);
|
return new CSharpCodeGenerator(chunkGeneratorContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Chunks.Generators
|
||||||
ClassName = className;
|
ClassName = className;
|
||||||
RootNamespaceName = rootNamespaceName;
|
RootNamespaceName = rootNamespaceName;
|
||||||
SourceFileName = sourceFileName;
|
SourceFileName = sourceFileName;
|
||||||
GenerateLinePragmas = string.IsNullOrEmpty(SourceFileName) ? false : true;
|
GenerateLinePragmas = !string.IsNullOrEmpty(SourceFileName);
|
||||||
Host = host;
|
Host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Razor.CodeGenerators
|
||||||
using (writer.BuildConstructor(Context.ClassName))
|
using (writer.BuildConstructor(Context.ClassName))
|
||||||
{
|
{
|
||||||
// Any constructor based logic that we need to add?
|
// Any constructor based logic that we need to add?
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddImports(ChunkTree chunkTree, CSharpCodeWriter writer, IEnumerable<string> defaultImports)
|
private void AddImports(ChunkTree chunkTree, CSharpCodeWriter writer, IEnumerable<string> defaultImports)
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ namespace Microsoft.AspNetCore.Razor.CodeGenerators
|
||||||
{
|
{
|
||||||
private const string InstanceMethodFormat = "{0}.{1}";
|
private const string InstanceMethodFormat = "{0}.{1}";
|
||||||
|
|
||||||
private static readonly char[] CStyleStringLiteralEscapeChars = new char[]
|
private static readonly char[] CStyleStringLiteralEscapeChars = {
|
||||||
{
|
|
||||||
'\r',
|
'\r',
|
||||||
'\t',
|
'\t',
|
||||||
'\"',
|
'\"',
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.CodeGenerators
|
||||||
{
|
{
|
||||||
public class CodeWriter : IDisposable
|
public class CodeWriter : IDisposable
|
||||||
{
|
{
|
||||||
private static readonly char[] NewLineCharacters = new char[] { '\r', '\n' };
|
private static readonly char[] NewLineCharacters = { '\r', '\n' };
|
||||||
|
|
||||||
private string _cache = string.Empty;
|
private string _cache = string.Empty;
|
||||||
private bool _dirty;
|
private bool _dirty;
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Parser
|
||||||
{
|
{
|
||||||
public partial class HtmlMarkupParser
|
public partial class HtmlMarkupParser
|
||||||
{
|
{
|
||||||
private static readonly char[] ValidAfterTypeAttributeNameCharacters =
|
private static readonly char[] ValidAfterTypeAttributeNameCharacters = { ' ', '\t', '\r', '\n', '\f', '=' };
|
||||||
new[] { ' ', '\t', '\r', '\n', '\f', '=' };
|
|
||||||
|
|
||||||
public override void ParseDocument()
|
public override void ParseDocument()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Razor.Text
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
LocationTagged<TValue> other = obj as LocationTagged<TValue>;
|
var other = obj as LocationTagged<TValue>;
|
||||||
if (ReferenceEquals(other, null))
|
if (ReferenceEquals(other, null))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Tokenizer.Symbols
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
SymbolBase<TType> other = obj as SymbolBase<TType>;
|
var other = obj as SymbolBase<TType>;
|
||||||
return other != null &&
|
return other != null &&
|
||||||
Start.Equals(other.Start) &&
|
Start.Equals(other.Start) &&
|
||||||
string.Equals(Content, other.Content, StringComparison.Ordinal) &&
|
string.Equals(Content, other.Content, StringComparison.Ordinal) &&
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
|
||||||
{
|
{
|
||||||
public class TagHelperTypeResolverTest
|
public class TagHelperTypeResolverTest
|
||||||
{
|
{
|
||||||
protected static readonly Type[] ValidTestableTagHelpers = new[]
|
protected static readonly Type[] ValidTestableTagHelpers =
|
||||||
{
|
{
|
||||||
typeof(Valid_PlainTagHelper),
|
typeof(Valid_PlainTagHelper),
|
||||||
typeof(Valid_InheritedTagHelper)
|
typeof(Valid_InheritedTagHelper)
|
||||||
};
|
};
|
||||||
|
|
||||||
protected static readonly Type[] InvalidTestableTagHelpers = new[]
|
protected static readonly Type[] InvalidTestableTagHelpers =
|
||||||
{
|
{
|
||||||
typeof(Invalid_AbstractTagHelper),
|
typeof(Invalid_AbstractTagHelper),
|
||||||
typeof(Invalid_GenericTagHelper<>),
|
typeof(Invalid_GenericTagHelper<>),
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Generator
|
||||||
private class CustomTagHelperAttributeCodeRenderer : TagHelperAttributeValueCodeRenderer
|
private class CustomTagHelperAttributeCodeRenderer : TagHelperAttributeValueCodeRenderer
|
||||||
{
|
{
|
||||||
public override void RenderAttributeValue(
|
public override void RenderAttributeValue(
|
||||||
TagHelperAttributeDescriptor attributeInfo,
|
TagHelperAttributeDescriptor attributeDescriptor,
|
||||||
CSharpCodeWriter writer,
|
CSharpCodeWriter writer,
|
||||||
CodeGeneratorContext context,
|
CodeGeneratorContext context,
|
||||||
Action<CSharpCodeWriter> renderAttributeValue,
|
Action<CSharpCodeWriter> renderAttributeValue,
|
||||||
|
|
@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Generator
|
||||||
{
|
{
|
||||||
writer.Write("**From custom attribute code renderer**: ");
|
writer.Write("**From custom attribute code renderer**: ");
|
||||||
|
|
||||||
base.RenderAttributeValue(attributeInfo, writer, context, renderAttributeValue, complexValue);
|
base.RenderAttributeValue(attributeDescriptor, writer, context, renderAttributeValue, complexValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,9 @@ namespace Microsoft.AspNetCore.Razor.Test.Generator
|
||||||
return Host.DecorateCodeGenerator(new TestCSharpCodeGenerator(context), context);
|
return Host.DecorateCodeGenerator(new TestCSharpCodeGenerator(context), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override RazorParser CreateParser(string fileName)
|
protected internal override RazorParser CreateParser(string sourceFileName)
|
||||||
{
|
{
|
||||||
var parser = base.CreateParser(fileName);
|
var parser = base.CreateParser(sourceFileName);
|
||||||
|
|
||||||
return new RazorParser(parser.CodeParser,
|
return new RazorParser(parser.CodeParser,
|
||||||
parser.MarkupParser,
|
parser.MarkupParser,
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser
|
||||||
private static void RunSyncContextTest<T>(T expected, Func<Action<T>, CallbackVisitor> ctor, Action<CallbackVisitor, T> call)
|
private static void RunSyncContextTest<T>(T expected, Func<Action<T>, CallbackVisitor> ctor, Action<CallbackVisitor, T> call)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<SynchronizationContext> mockContext = new Mock<SynchronizationContext>();
|
var mockContext = new Mock<SynchronizationContext>();
|
||||||
mockContext.Setup(c => c.Post(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()))
|
mockContext.Setup(c => c.Post(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()))
|
||||||
.Callback<SendOrPostCallback, object>((callback, state) => { callback(expected); });
|
.Callback<SendOrPostCallback, object>((callback, state) => { callback(expected); });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser
|
||||||
public void EndBlockAddsCurrentBlockToParentBlock()
|
public void EndBlockAddsCurrentBlockToParentBlock()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<ParserVisitor> mockListener = new Mock<ParserVisitor>();
|
var mockListener = new Mock<ParserVisitor>();
|
||||||
var context = SetupTestContext("phoo");
|
var context = SetupTestContext("phoo");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var factory = SpanFactory.CreateCsHtml();
|
var factory = SpanFactory.CreateCsHtml();
|
||||||
Mock<ParserVisitor> mockListener = new Mock<ParserVisitor>();
|
var mockListener = new Mock<ParserVisitor>();
|
||||||
var context = SetupTestContext("phoo");
|
var context = SetupTestContext("phoo");
|
||||||
|
|
||||||
var builder = new SpanBuilder()
|
var builder = new SpanBuilder()
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser
|
||||||
public void VisitSendsDocumentToVisitor()
|
public void VisitSendsDocumentToVisitor()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
var targetMock = new Mock<ParserVisitor>();
|
||||||
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
||||||
var errorSink = new ErrorSink();
|
var errorSink = new ErrorSink();
|
||||||
var results = new ParserResults(root,
|
var results = new ParserResults(root,
|
||||||
|
|
@ -35,10 +35,10 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser
|
||||||
public void VisitSendsErrorsToVisitor()
|
public void VisitSendsErrorsToVisitor()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
var targetMock = new Mock<ParserVisitor>();
|
||||||
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
||||||
var errorSink = new ErrorSink();
|
var errorSink = new ErrorSink();
|
||||||
List<RazorError> errors = new List<RazorError>
|
var errors = new List<RazorError>
|
||||||
{
|
{
|
||||||
new RazorError("Foo", new SourceLocation(1, 0, 1), length: 3),
|
new RazorError("Foo", new SourceLocation(1, 0, 1), length: 3),
|
||||||
new RazorError("Bar", new SourceLocation(2, 0, 2), length: 3),
|
new RazorError("Bar", new SourceLocation(2, 0, 2), length: 3),
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser
|
||||||
public void VisitCallsOnCompleteWhenAllNodesHaveBeenVisited()
|
public void VisitCallsOnCompleteWhenAllNodesHaveBeenVisited()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Mock<ParserVisitor> targetMock = new Mock<ParserVisitor>();
|
var targetMock = new Mock<ParserVisitor>();
|
||||||
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
var root = new BlockBuilder() { Type = BlockType.Comment }.Build();
|
||||||
var errorSink = new ErrorSink();
|
var errorSink = new ErrorSink();
|
||||||
errorSink.OnError(new RazorError("Foo", new SourceLocation(1, 0, 1), length: 3));
|
errorSink.OnError(new RazorError("Foo", new SourceLocation(1, 0, 1), length: 3));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue