Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2242,8 +2242,8 @@ public void Rewrites_ComponentDirectiveAttributes()
.BindAttributeParameter(p =>
{
p.Name = "event";
p.PropertyName = "Event";
p.TypeName = typeof(string).FullName;
p.SetMetadata(PropertyName("Event"));
}))
.Build(),
];
Expand Down Expand Up @@ -2288,8 +2288,8 @@ public void Rewrites_MinimizedComponentDirectiveAttributes()
.BindAttributeParameter(p =>
{
p.Name = "param";
p.PropertyName = "Param";
p.TypeName = typeof(string).FullName;
p.SetMetadata(PropertyName("Param"));
}))
.Build(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2465,8 +2465,8 @@ public void Rewrites_ComponentDirectiveAttributes()
.BindAttributeParameter(p =>
{
p.Name = "event";
p.PropertyName = "Event";
p.TypeName = typeof(string).FullName;
p.SetMetadata(PropertyName("Event"));
}))
.Build(),
];
Expand Down Expand Up @@ -2511,8 +2511,8 @@ public void Rewrites_MinimizedComponentDirectiveAttributes()
.BindAttributeParameter(p =>
{
p.Name = "param";
p.PropertyName = "Param";
p.TypeName = typeof(string).FullName;
p.SetMetadata(PropertyName("Param"));
}))
.Build(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,57 +164,52 @@ private static TagHelperDescriptor CreateFallbackBindTagHelper()
attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "format";
parameter.PropertyName = "Format";
parameter.TypeName = typeof(string).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Fallback_Format);

parameter.SetMetadata(Parameters.Format);
});

attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "event";
parameter.PropertyName = "Event";
parameter.TypeName = typeof(string).FullName;
parameter.SetDocumentation(
DocumentationDescriptor.From(
DocumentationId.BindTagHelper_Fallback_Event, attributeName));

parameter.SetMetadata(Parameters.Event);
});

attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "culture";
parameter.PropertyName = "Culture";
parameter.TypeName = typeof(CultureInfo).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Culture);

parameter.SetMetadata(Parameters.Culture);
});

attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "get";
parameter.PropertyName = "Get";
parameter.TypeName = typeof(object).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Get);

parameter.SetMetadata(Parameters.Get);
parameter.BindAttributeGetSet = true;
});

attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "set";
parameter.PropertyName = "Set";
parameter.TypeName = typeof(Delegate).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Set);

parameter.SetMetadata(Parameters.Set);
});

attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "after";
parameter.PropertyName = "After";
parameter.TypeName = typeof(Delegate).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_After);

parameter.SetMetadata(Parameters.After);
});
});

Expand Down Expand Up @@ -470,61 +465,56 @@ private static TagHelperDescriptor CreateElementBindTagHelper(
a.BindAttributeParameter(parameter =>
{
parameter.Name = "format";
parameter.PropertyName = formatName;
parameter.TypeName = typeof(string).FullName;
parameter.SetDocumentation(
DocumentationDescriptor.From(
DocumentationId.BindTagHelper_Element_Format,
attributeName));

parameter.SetMetadata(PropertyName(formatName));
});

a.BindAttributeParameter(parameter =>
{
parameter.Name = "event";
parameter.PropertyName = eventName;
parameter.TypeName = typeof(string).FullName;
parameter.SetDocumentation(
DocumentationDescriptor.From(
DocumentationId.BindTagHelper_Element_Event,
attributeName));

parameter.SetMetadata(PropertyName(eventName));
});

a.BindAttributeParameter(parameter =>
{
parameter.Name = "culture";
parameter.PropertyName = "Culture";
parameter.TypeName = typeof(CultureInfo).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Culture);

parameter.SetMetadata(Parameters.Culture);
});

a.BindAttributeParameter(parameter =>
{
parameter.Name = "get";
parameter.PropertyName = "Get";
parameter.TypeName = typeof(object).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Get);

parameter.SetMetadata(Parameters.Get);
parameter.BindAttributeGetSet = true;
});

a.BindAttributeParameter(parameter =>
{
parameter.Name = "set";
parameter.PropertyName = "Set";
parameter.TypeName = typeof(Delegate).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Set);

parameter.SetMetadata(Parameters.Set);
});

a.BindAttributeParameter(parameter =>
{
parameter.Name = "after";
parameter.PropertyName = "After";
parameter.TypeName = typeof(Delegate).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_After);

parameter.SetMetadata(Parameters.After);
});
});

Expand Down Expand Up @@ -676,28 +666,26 @@ private static void AddComponentBindTagHelpers(TagHelperDescriptor tagHelper, re
attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "get";
parameter.PropertyName = "Get";
parameter.TypeName = typeof(object).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Get);

parameter.SetMetadata(Parameters.Get);
parameter.BindAttributeGetSet = true;
});

attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "set";
parameter.PropertyName = "Set";
parameter.TypeName = typeof(Delegate).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_Set);

parameter.SetMetadata(Parameters.Set);
});

attribute.BindAttributeParameter(parameter =>
{
parameter.Name = "after";
parameter.PropertyName = "After";
parameter.TypeName = typeof(Delegate).FullName;
parameter.SetDocumentation(DocumentationDescriptor.BindTagHelper_Element_After);

parameter.SetMetadata(Parameters.After);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,12 @@ private static TagHelperDescriptor CreateTagHelper(
a.BindAttributeParameter(parameter =>
{
parameter.Name = "preventDefault";
parameter.PropertyName = "PreventDefault";
parameter.TypeName = typeof(bool).FullName;
parameter.SetDocumentation(
DocumentationDescriptor.From(
DocumentationId.EventHandlerTagHelper_PreventDefault,
attributeName));

parameter.SetMetadata(Parameters.PreventDefault);
});
}

Expand All @@ -255,13 +254,12 @@ private static TagHelperDescriptor CreateTagHelper(
a.BindAttributeParameter(parameter =>
{
parameter.Name = "stopPropagation";
parameter.PropertyName = "StopPropagation";
parameter.TypeName = typeof(bool).FullName;
parameter.SetDocumentation(
DocumentationDescriptor.From(
DocumentationId.EventHandlerTagHelper_StopPropagation,
attributeName));

parameter.SetMetadata(Parameters.StopPropagation);
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.Components;

namespace Microsoft.AspNetCore.Razor.Language;

Expand Down Expand Up @@ -49,9 +48,4 @@ public static void AsDictionary(
builder.IndexerAttributeNamePrefix = attributeNamePrefix;
builder.IndexerValueTypeName = valueTypeName;
}

internal static void SetMetadata(this BoundAttributeParameterDescriptorBuilder builder, KeyValuePair<string, string> pair)
{
builder.SetMetadata(MetadataCollection.Create(pair));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,4 @@ public static bool IsDefaultKind(this BoundAttributeParameterDescriptor paramete

return parameter.Parent.Parent.Kind == TagHelperConventions.DefaultKind;
}

public static string? GetPropertyName(this BoundAttributeParameterDescriptor parameter)
{
ArgHelper.ThrowIfNull(parameter);

parameter.Metadata.TryGetValue(TagHelperMetadata.Common.PropertyName, out var propertyName);
return propertyName;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.AspNetCore.Razor.Utilities;
Expand All @@ -10,86 +9,52 @@ namespace Microsoft.AspNetCore.Razor.Language;

public sealed class BoundAttributeParameterDescriptor : TagHelperObject<BoundAttributeParameterDescriptor>
{
[Flags]
private enum BoundAttributeParameterFlags
{
CaseSensitive = 1 << 0,
IsEnum = 1 << 1,
IsStringProperty = 1 << 2,
IsBooleanProperty = 1 << 3
}

private readonly BoundAttributeParameterFlags _flags;
private readonly DocumentationObject _documentationObject;

private BoundAttributeDescriptor? _parent;
private string? _displayName;

public BoundAttributeParameterFlags Flags => _flags;
public string Name { get; }
public string TypeName { get; }
public string DisplayName { get; }
public string PropertyName { get; }
public string TypeName => TypeNameObject.GetTypeName().AssumeNotNull();
public string DisplayName => _displayName ??= ":" + Name;

public string? Documentation => DocumentationObject.GetText();

public bool CaseSensitive => (_flags & BoundAttributeParameterFlags.CaseSensitive) != 0;
public bool IsEnum => (_flags & BoundAttributeParameterFlags.IsEnum) != 0;
public bool IsStringProperty => (_flags & BoundAttributeParameterFlags.IsStringProperty) != 0;
public bool IsBooleanProperty => (_flags & BoundAttributeParameterFlags.IsBooleanProperty) != 0;
internal TypeNameObject TypeNameObject { get; }
internal DocumentationObject DocumentationObject { get; }

public MetadataCollection Metadata { get; }
public bool CaseSensitive => _flags.IsFlagSet(BoundAttributeParameterFlags.CaseSensitive);
public bool IsEnum => _flags.IsFlagSet(BoundAttributeParameterFlags.IsEnum);
public bool IsStringProperty => TypeNameObject.IsString;
public bool IsBooleanProperty => TypeNameObject.IsBoolean;
public bool BindAttributeGetSet => _flags.IsFlagSet(BoundAttributeParameterFlags.BindAttributeGetSet);

internal BoundAttributeParameterDescriptor(
BoundAttributeParameterFlags flags,
string name,
string typeName,
bool isEnum,
string propertyName,
TypeNameObject typeNameObject,
DocumentationObject documentationObject,
string displayName,
bool caseSensitive,
MetadataCollection metadata,
ImmutableArray<RazorDiagnostic> diagnostics)
: base(diagnostics)
{
Name = name;
TypeName = typeName;
_documentationObject = documentationObject;
DisplayName = displayName;
Metadata = metadata ?? MetadataCollection.Empty;

BoundAttributeParameterFlags flags = 0;

if (isEnum)
{
flags |= BoundAttributeParameterFlags.IsEnum;
}

if (caseSensitive)
{
flags |= BoundAttributeParameterFlags.CaseSensitive;
}

if (typeName == typeof(string).FullName || typeName == "string")
{
flags |= BoundAttributeParameterFlags.IsStringProperty;
}

if (typeName == typeof(bool).FullName || typeName == "bool")
{
flags |= BoundAttributeParameterFlags.IsBooleanProperty;
}

_flags = flags;

Name = name;
PropertyName = propertyName;
TypeNameObject = typeNameObject;
DocumentationObject = documentationObject;
}

private protected override void BuildChecksum(in Checksum.Builder builder)
{
builder.AppendData((byte)_flags);
builder.AppendData(Name);
builder.AppendData(TypeName);
builder.AppendData(DisplayName);
builder.AppendData(PropertyName);

TypeNameObject.AppendToChecksum(in builder);
DocumentationObject.AppendToChecksum(in builder);

builder.AppendData(CaseSensitive);
builder.AppendData(IsEnum);
builder.AppendData(IsBooleanProperty);
builder.AppendData(IsStringProperty);
builder.AppendData(Metadata.Checksum);
}

public BoundAttributeDescriptor Parent
Expand All @@ -103,10 +68,6 @@ internal void SetParent(BoundAttributeDescriptor parent)
_parent = parent;
}

public string? Documentation => _documentationObject.GetText();

internal DocumentationObject DocumentationObject => _documentationObject;

public override string ToString()
=> DisplayName ?? base.ToString()!;
=> DisplayName;
}
Loading