forked from dotnet/razor-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Directive attributes part 1: Support parameters in bound attributes (d…
…otnet/razor#597) * Directive attributes part 1: Support parameters in bound attributes * update * Fix test * feedback * Updated design * Do case sensitive comparison * more * Bug fix \n\nCommit migrated from dotnet/razor@9bbf240 Commit migrated from dotnet/aspnetcore@5bad5de7ee95
- Loading branch information
1 parent
1bd2225
commit 27bd36e
Showing
60 changed files
with
1,088 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Microsoft.AspNetCore.Razor.Language/src/BoundAttributeParameterDescriptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Language | ||
{ | ||
public abstract class BoundAttributeParameterDescriptor : IEquatable<BoundAttributeParameterDescriptor> | ||
{ | ||
protected BoundAttributeParameterDescriptor(string kind) | ||
{ | ||
Kind = kind; | ||
} | ||
|
||
public string Kind { get; } | ||
|
||
public bool IsEnum { get; protected set; } | ||
|
||
public bool IsStringProperty { get; protected set; } | ||
|
||
public bool IsBooleanProperty { get; protected set; } | ||
|
||
public string Name { get; protected set; } | ||
|
||
public string TypeName { get; protected set; } | ||
|
||
public string Documentation { get; protected set; } | ||
|
||
public string DisplayName { get; protected set; } | ||
|
||
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; } | ||
|
||
public IReadOnlyDictionary<string, string> Metadata { get; protected set; } | ||
|
||
public bool HasErrors | ||
{ | ||
get | ||
{ | ||
var errors = Diagnostics.Any(diagnostic => diagnostic.Severity == RazorDiagnosticSeverity.Error); | ||
|
||
return errors; | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return DisplayName ?? base.ToString(); | ||
} | ||
|
||
public bool Equals(BoundAttributeParameterDescriptor other) | ||
{ | ||
return BoundAttributeParameterDescriptorComparer.Default.Equals(this, other); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return Equals(obj as BoundAttributeParameterDescriptor); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return BoundAttributeParameterDescriptorComparer.Default.GetHashCode(this); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Microsoft.AspNetCore.Razor.Language/src/BoundAttributeParameterDescriptorBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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.Collections.Generic; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Language | ||
{ | ||
public abstract class BoundAttributeParameterDescriptorBuilder | ||
{ | ||
public abstract string Name { get; set; } | ||
|
||
public abstract string TypeName { get; set; } | ||
|
||
public abstract bool IsEnum { get; set; } | ||
|
||
public abstract string Documentation { get; set; } | ||
|
||
public abstract string DisplayName { get; set; } | ||
|
||
public abstract IDictionary<string, string> Metadata { get; } | ||
|
||
public abstract RazorDiagnosticCollection Diagnostics { get; } | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/Microsoft.AspNetCore.Razor.Language/src/BoundAttributeParameterDescriptorComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.Extensions.Internal; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Language | ||
{ | ||
internal class BoundAttributeParameterDescriptorComparer : IEqualityComparer<BoundAttributeParameterDescriptor> | ||
{ | ||
/// <summary> | ||
/// A default instance of the <see cref="BoundAttributeParameterDescriptorComparer"/>. | ||
/// </summary> | ||
public static readonly BoundAttributeParameterDescriptorComparer Default = new BoundAttributeParameterDescriptorComparer(); | ||
|
||
/// <summary> | ||
/// A default instance of the <see cref="BoundAttributeParameterDescriptorComparer"/> that does case-sensitive comparison. | ||
/// </summary> | ||
internal static readonly BoundAttributeParameterDescriptorComparer CaseSensitive = | ||
new BoundAttributeParameterDescriptorComparer(caseSensitive: true); | ||
|
||
private readonly StringComparer _stringComparer; | ||
private readonly StringComparison _stringComparison; | ||
|
||
private BoundAttributeParameterDescriptorComparer(bool caseSensitive = false) | ||
{ | ||
if (caseSensitive) | ||
{ | ||
_stringComparer = StringComparer.Ordinal; | ||
_stringComparison = StringComparison.Ordinal; | ||
} | ||
else | ||
{ | ||
_stringComparer = StringComparer.OrdinalIgnoreCase; | ||
_stringComparison = StringComparison.OrdinalIgnoreCase; | ||
} | ||
} | ||
|
||
public virtual bool Equals(BoundAttributeParameterDescriptor descriptorX, BoundAttributeParameterDescriptor descriptorY) | ||
{ | ||
if (object.ReferenceEquals(descriptorX, descriptorY)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (descriptorX == null ^ descriptorY == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return | ||
string.Equals(descriptorX.Kind, descriptorY.Kind, StringComparison.Ordinal) && | ||
descriptorX.IsEnum == descriptorY.IsEnum && | ||
string.Equals(descriptorX.Name, descriptorY.Name, _stringComparison) && | ||
string.Equals(descriptorX.TypeName, descriptorY.TypeName, StringComparison.Ordinal) && | ||
string.Equals(descriptorX.Documentation, descriptorY.Documentation, StringComparison.Ordinal) && | ||
string.Equals(descriptorX.DisplayName, descriptorY.DisplayName, StringComparison.Ordinal) && | ||
Enumerable.SequenceEqual( | ||
descriptorX.Metadata.OrderBy(propertyX => propertyX.Key, StringComparer.Ordinal), | ||
descriptorY.Metadata.OrderBy(propertyY => propertyY.Key, StringComparer.Ordinal)); | ||
} | ||
|
||
public virtual int GetHashCode(BoundAttributeParameterDescriptor descriptor) | ||
{ | ||
if (descriptor == null) | ||
{ | ||
throw new ArgumentNullException(nameof(descriptor)); | ||
} | ||
|
||
var hash = HashCodeCombiner.Start(); | ||
hash.Add(descriptor.Kind); | ||
hash.Add(descriptor.Name, _stringComparer); | ||
|
||
return hash.CombinedHash; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.