Making HashCodeCombiner usage non-fluent

React to https://github.com/aspnet/Common/issues/40
This commit is contained in:
Pranav K 2015-09-21 13:56:23 -07:00
parent 153ed57d66
commit 388362245f
22 changed files with 137 additions and 115 deletions

View File

@ -49,10 +49,10 @@ namespace Microsoft.AspNet.Razor.Test.Internal
public override int GetHashCode(TagHelperDescriptor descriptor)
{
var hashCodeCombiner = HashCodeCombiner.Start()
.Add(base.GetHashCode(descriptor))
.Add(descriptor.TagName, StringComparer.Ordinal)
.Add(descriptor.Prefix, StringComparer.Ordinal);
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(base.GetHashCode(descriptor));
hashCodeCombiner.Add(descriptor.TagName, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.Prefix, StringComparer.Ordinal);
if (descriptor.DesignTimeDescriptor != null)
{

View File

@ -38,15 +38,16 @@ namespace Microsoft.AspNet.Razor.Test.Internal
public int GetHashCode(TagHelperAttributeDescriptor descriptor)
{
return HashCodeCombiner.Start()
.Add(descriptor.IsIndexer)
.Add(descriptor.Name, StringComparer.Ordinal)
.Add(descriptor.PropertyName, StringComparer.Ordinal)
.Add(descriptor.TypeName, StringComparer.Ordinal)
.Add(descriptor.IsStringProperty)
.Add(TagHelperAttributeDesignTimeDescriptorComparer.Default.GetHashCode(
descriptor.DesignTimeDescriptor))
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(descriptor.IsIndexer);
hashCodeCombiner.Add(descriptor.Name, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.PropertyName, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.TypeName, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.IsStringProperty);
hashCodeCombiner.Add(TagHelperAttributeDesignTimeDescriptorComparer.Default.GetHashCode(
descriptor.DesignTimeDescriptor));
return hashCodeCombiner;
}
}
}

View File

@ -35,11 +35,11 @@ namespace Microsoft.AspNet.Razor.Test.Internal
public int GetHashCode(TagHelperAttributeDesignTimeDescriptor descriptor)
{
return HashCodeCombiner
.Start()
.Add(descriptor.Summary, StringComparer.Ordinal)
.Add(descriptor.Remarks, StringComparer.Ordinal)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(descriptor.Summary, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.Remarks, StringComparer.Ordinal);
return hashCodeCombiner;
}
}
}

View File

@ -33,12 +33,13 @@ namespace Microsoft.AspNet.Razor.Test.Internal
public int GetHashCode(TagHelperDesignTimeDescriptor descriptor)
{
return HashCodeCombiner
.Start()
.Add(descriptor.Summary, StringComparer.Ordinal)
.Add(descriptor.Remarks, StringComparer.Ordinal)
.Add(descriptor.OutputElementHint, StringComparer.Ordinal)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(descriptor.Summary, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.Remarks, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.OutputElementHint, StringComparer.Ordinal);
return hashCodeCombiner;
}
}
}

View File

@ -54,11 +54,12 @@ namespace Microsoft.AspNet.Razor.Chunks.Generators
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(Name, StringComparer.Ordinal)
.Add(Prefix)
.Add(Suffix)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Name, StringComparer.Ordinal);
hashCodeCombiner.Add(Prefix);
hashCodeCombiner.Add(Suffix);
return hashCodeCombiner;
}
}
}

View File

@ -71,11 +71,13 @@ namespace Microsoft.AspNet.Razor.Chunks.Generators
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(Prefix)
.Add(Value)
.Add(ValueGenerator)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Prefix);
hashCodeCombiner.Add(Value);
hashCodeCombiner.Add(ValueGenerator);
return hashCodeCombiner;
}
}
}

View File

@ -177,13 +177,15 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
public override int GetHashCode()
{
// Hash code should include only immutable properties.
return HashCodeCombiner.Start()
.Add(WriteMethodName, StringComparer.Ordinal)
.Add(WriteLiteralMethodName, StringComparer.Ordinal)
.Add(WriteToMethodName, StringComparer.Ordinal)
.Add(WriteLiteralToMethodName, StringComparer.Ordinal)
.Add(ExecuteMethodName, StringComparer.Ordinal)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(WriteMethodName, StringComparer.Ordinal);
hashCodeCombiner.Add(WriteLiteralMethodName, StringComparer.Ordinal);
hashCodeCombiner.Add(WriteToMethodName, StringComparer.Ordinal);
hashCodeCombiner.Add(WriteLiteralToMethodName, StringComparer.Ordinal);
hashCodeCombiner.Add(ExecuteMethodName, StringComparer.Ordinal);
return hashCodeCombiner;
}
public static bool operator ==(GeneratedClassContext left, GeneratedClassContext right)

View File

@ -32,10 +32,11 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(DocumentLocation)
.Add(GeneratedLocation)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(DocumentLocation);
hashCodeCombiner.Add(GeneratedLocation);
return hashCodeCombiner;
}
public static bool operator ==(LineMapping left, LineMapping right)

View File

@ -44,12 +44,13 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(AbsoluteIndex)
.Add(ContentLength)
.Add(LineIndex)
.Add(CharacterIndex)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(AbsoluteIndex);
hashCodeCombiner.Add(ContentLength);
hashCodeCombiner.Add(LineIndex);
hashCodeCombiner.Add(CharacterIndex);
return hashCodeCombiner;
}
public override string ToString()

View File

@ -65,10 +65,11 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
public override int GetHashCode()
{
// Hash code should include only immutable properties but Equals also checks the type.
return HashCodeCombiner.Start()
.Add(TypeHashCode)
.Add(AutoCompleteAtEndOfSpan)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(TypeHashCode);
hashCodeCombiner.Add(AutoCompleteAtEndOfSpan);
return hashCodeCombiner.CombinedHash;
}
}
}

View File

@ -60,10 +60,11 @@ namespace Microsoft.AspNet.Razor.Editor
public override int GetHashCode()
{
// Hash code should include only immutable properties and base has none.
return HashCodeCombiner.Start()
.Add(Keywords)
.Add(AcceptTrailingDot)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Keywords);
hashCodeCombiner.Add(AcceptTrailingDot);
return hashCodeCombiner;
}
protected override PartialParseResult CanAcceptChange(Span target, TextChange normalizedChange)

View File

@ -129,11 +129,12 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(Type)
.Add(ChunkGenerator)
.Add(Children)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Type);
hashCodeCombiner.Add(ChunkGenerator);
hashCodeCombiner.Add(Children);
return hashCodeCombiner;
}
public IEnumerable<Span> Flatten()
@ -222,13 +223,14 @@ namespace Microsoft.AspNet.Razor.Parser.SyntaxTree
public override int GetEquivalenceHash()
{
var combiner = HashCodeCombiner.Start().Add(Type);
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Type);
foreach (var child in Children)
{
combiner.Add(child.GetEquivalenceHash());
hashCodeCombiner.Add(child.GetEquivalenceHash());
}
return combiner.CombinedHash;
return hashCodeCombiner.CombinedHash;
}
}
}

View File

@ -127,11 +127,12 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers
/// <inheritdoc />
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(base.GetHashCode())
.Add(TagName, StringComparer.OrdinalIgnoreCase)
.Add(Attributes)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(base.GetHashCode());
hashCodeCombiner.Add(TagName, StringComparer.OrdinalIgnoreCase);
hashCodeCombiner.Add(Attributes);
return hashCodeCombiner;
}
}
}

View File

@ -62,10 +62,11 @@ namespace Microsoft.AspNet.Razor
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(Message, StringComparer.Ordinal)
.Add(Location)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Message, StringComparer.Ordinal);
hashCodeCombiner.Add(Location);
return hashCodeCombiner;
}
public bool Equals(RazorError other)

View File

@ -96,10 +96,11 @@ namespace Microsoft.AspNet.Razor
/// <inheritdoc />
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(FilePath, StringComparer.Ordinal)
.Add(AbsoluteIndex)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(FilePath, StringComparer.Ordinal);
hashCodeCombiner.Add(AbsoluteIndex);
return hashCodeCombiner;
}
/// <inheritdoc />

View File

@ -68,11 +68,11 @@ namespace Microsoft.AspNet.Razor.TagHelpers
throw new ArgumentNullException(nameof(descriptor));
}
var hashCodeCombiner = HashCodeCombiner.Start()
.Add(descriptor.TypeName, StringComparer.Ordinal)
.Add(descriptor.TagName, StringComparer.OrdinalIgnoreCase)
.Add(descriptor.AssemblyName, StringComparer.Ordinal)
.Add(descriptor.TagStructure);
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(descriptor.TypeName, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.TagName, StringComparer.OrdinalIgnoreCase);
hashCodeCombiner.Add(descriptor.AssemblyName, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.TagStructure);
var attributes = descriptor.RequiredAttributes.OrderBy(
attribute => attribute,

View File

@ -54,10 +54,11 @@ namespace Microsoft.AspNet.Razor.TagHelpers
throw new ArgumentNullException(nameof(descriptor));
}
return HashCodeCombiner.Start()
.Add(descriptor.AssemblyName, StringComparer.Ordinal)
.Add(descriptor.TypeName, StringComparer.Ordinal)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(descriptor.AssemblyName, StringComparer.Ordinal);
hashCodeCombiner.Add(descriptor.TypeName, StringComparer.Ordinal);
return hashCodeCombiner;
}
}
}

View File

@ -55,10 +55,11 @@ namespace Microsoft.AspNet.Razor.Text
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(Location)
.Add(Value)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Location);
hashCodeCombiner.Add(Value);
return hashCodeCombiner.CombinedHash;
}
public override string ToString()

View File

@ -146,14 +146,15 @@ namespace Microsoft.AspNet.Razor.Text
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(OldPosition)
.Add(NewPosition)
.Add(OldLength)
.Add(NewLength)
.Add(OldBuffer)
.Add(NewBuffer)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(OldPosition);
hashCodeCombiner.Add(NewPosition);
hashCodeCombiner.Add(OldLength);
hashCodeCombiner.Add(NewLength);
hashCodeCombiner.Add(OldBuffer);
hashCodeCombiner.Add(NewBuffer);
return hashCodeCombiner;
}
public string ApplyChange(string content, int changeOffset)

View File

@ -50,10 +50,11 @@ namespace Microsoft.AspNet.Razor.Tokenizer.Symbols
public override int GetHashCode()
{
// Hash code should include only immutable properties.
return HashCodeCombiner.Start()
.Add(Content, StringComparer.Ordinal)
.Add(Type)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Content, StringComparer.Ordinal);
hashCodeCombiner.Add(Type);
return hashCodeCombiner;
}
public override string ToString()

View File

@ -50,11 +50,12 @@ namespace Microsoft.AspNet.Razor.Test.Generator
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(Kind)
.Add(Start)
.Add(End)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(Kind);
hashCodeCombiner.Add(Start);
hashCodeCombiner.Add(End);
return hashCodeCombiner;
}
}
}

View File

@ -291,11 +291,12 @@ namespace Microsoft.AspNet.Razor.TagHelpers
public int GetHashCode(TagHelperDirectiveDescriptor directiveDescriptor)
{
return HashCodeCombiner.Start()
.Add(base.GetHashCode())
.Add(directiveDescriptor.DirectiveText)
.Add(directiveDescriptor.DirectiveType)
.CombinedHash;
var hashCodeCombiner = HashCodeCombiner.Start();
hashCodeCombiner.Add(base.GetHashCode());
hashCodeCombiner.Add(directiveDescriptor.DirectiveText);
hashCodeCombiner.Add(directiveDescriptor.DirectiveType);
return hashCodeCombiner;
}
}