From cadc2fc67ee73a1a6f562230657a97a0998960d0 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 13 Feb 2014 14:24:15 -0800 Subject: [PATCH] Add comparison methods to mapping classes. This involved adding Equals and == methods to LineMapping.cs and MappingLocation.cs. --- .../Compiler/LineMappings/LineMapping.cs | 33 +++++++++++++++++++ .../Compiler/LineMappings/MappingLocation.cs | 25 ++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs index 8da0e932f8..a0219c0664 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/LineMapping.cs @@ -3,7 +3,40 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler { public class LineMapping { + public LineMapping() + : this(documentLocation: null, generatedLocation: null) + { + } + + public LineMapping(MappingLocation documentLocation, MappingLocation generatedLocation) + { + DocumentLocation = documentLocation; + GeneratedLocation = generatedLocation; + } + public MappingLocation DocumentLocation { get; set; } public MappingLocation GeneratedLocation { get; set; } + + public override bool Equals(object obj) + { + LineMapping other = obj as LineMapping; + return DocumentLocation.Equals(other.DocumentLocation) && + GeneratedLocation.Equals(other.GeneratedLocation); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + public static bool operator ==(LineMapping left, LineMapping right) + { + return left.Equals(right); + } + + public static bool operator !=(LineMapping left, LineMapping right) + { + return !left.Equals(right); + } } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs index 40a956c34d..2f5b93fd0d 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/LineMappings/MappingLocation.cs @@ -18,5 +18,30 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler public int AbsoluteIndex { get; set; } public int LineIndex { get; set; } public int CharacterIndex { get; set; } + + public override bool Equals(object obj) + { + MappingLocation other = obj as MappingLocation; + + return AbsoluteIndex == other.AbsoluteIndex && + ContentLength == other.ContentLength && + LineIndex == other.LineIndex && + CharacterIndex == other.CharacterIndex; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + public static bool operator ==(MappingLocation left, MappingLocation right) + { + return left.Equals(right); + } + + public static bool operator !=(MappingLocation left, MappingLocation right) + { + return !left.Equals(right); + } } }