Add comparison methods to mapping classes.

This involved adding Equals and == methods to LineMapping.cs and MappingLocation.cs.
This commit is contained in:
N. Taylor Mullen 2014-02-13 14:24:15 -08:00
parent fa342287ad
commit cadc2fc67e
2 changed files with 58 additions and 0 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}