Make LineMapping public

This commit is contained in:
Ajay Bhargav Baaskaran 2017-02-03 14:15:54 -08:00
parent 3f5d1bb2d6
commit adf18d4810
3 changed files with 21 additions and 15 deletions

View File

@ -1,40 +1,46 @@
// 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.Globalization;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
namespace Microsoft.AspNetCore.Razor.Evolution
{
internal class LineMapping
public sealed class LineMapping : IEquatable<LineMapping>
{
public LineMapping(SourceSpan documentLocation, SourceSpan generatedLocation)
public LineMapping(SourceSpan originalSourceSpan, SourceSpan generatedSourceSpan)
{
DocumentLocation = documentLocation;
GeneratedLocation = generatedLocation;
OriginalSpan = originalSourceSpan;
GeneratedSpan = generatedSourceSpan;
}
public SourceSpan DocumentLocation { get; }
public SourceSpan OriginalSpan { get; }
public SourceSpan GeneratedLocation { get; }
public SourceSpan GeneratedSpan { get; }
public override bool Equals(object obj)
{
var other = obj as LineMapping;
return Equals(other);
}
public bool Equals(LineMapping other)
{
if (ReferenceEquals(other, null))
{
return false;
}
return DocumentLocation.Equals(other.DocumentLocation) &&
GeneratedLocation.Equals(other.GeneratedLocation);
return OriginalSpan.Equals(other.OriginalSpan) &&
GeneratedSpan.Equals(other.GeneratedSpan);
}
public override int GetHashCode()
{
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(DocumentLocation);
hashCodeCombiner.Add(GeneratedLocation);
hashCodeCombiner.Add(OriginalSpan);
hashCodeCombiner.Add(GeneratedSpan);
return hashCodeCombiner;
}
@ -73,7 +79,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture, "{0} -> {1}", DocumentLocation, GeneratedLocation);
return string.Format(CultureInfo.CurrentCulture, "{0} -> {1}", OriginalSpan, GeneratedSpan);
}
}
}

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
public string GeneratedCode { get; set; }
internal IReadOnlyList<LineMapping> LineMappings { get; set; }
public IReadOnlyList<LineMapping> LineMappings { get; set; }
public IReadOnlyList<RazorError> Diagnostics { get; set; }
}

View File

@ -20,10 +20,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
var lineMapping = csharpDocument.LineMappings[i];
builder.Append("Source Location: ");
AppendMappingLocation(builder, lineMapping.DocumentLocation, sourceContent);
AppendMappingLocation(builder, lineMapping.OriginalSpan, sourceContent);
builder.Append("Generated Location: ");
AppendMappingLocation(builder, lineMapping.GeneratedLocation, csharpDocument.GeneratedCode);
AppendMappingLocation(builder, lineMapping.GeneratedSpan, csharpDocument.GeneratedCode);
builder.AppendLine();
}