Added Name and Documentation to DirectiveTokenDescriptor

This commit is contained in:
Ajay Bhargav Baaskaran 2017-10-04 16:56:11 -07:00
parent 4d737af167
commit 7002dbf20a
18 changed files with 649 additions and 44 deletions

View File

@ -16,8 +16,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddTypeToken().AddMemberToken(); builder
.AddTypeToken(Resources.InjectDirective_TypeToken_Name, Resources.InjectDirective_TypeToken_Description)
.AddMemberToken(Resources.InjectDirective_MemberToken_Name, Resources.InjectDirective_MemberToken_Description);
builder.Usage = DirectiveUsage.FileScopedMultipleOccurring; builder.Usage = DirectiveUsage.FileScopedMultipleOccurring;
builder.Description = Resources.InjectDirective_Description;
}); });
public static IRazorEngineBuilder Register(IRazorEngineBuilder builder) public static IRazorEngineBuilder Register(IRazorEngineBuilder builder)

View File

@ -16,8 +16,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddTypeToken(); builder.AddTypeToken(Resources.ModelDirective_TypeToken_Name, Resources.ModelDirective_TypeToken_Description);
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring; builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
builder.Description = Resources.ModelDirective_Description;
}); });
public static IRazorEngineBuilder Register(IRazorEngineBuilder builder) public static IRazorEngineBuilder Register(IRazorEngineBuilder builder)

View File

@ -24,6 +24,118 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
internal static string FormatArgumentCannotBeNullOrEmpy() internal static string FormatArgumentCannotBeNullOrEmpy()
=> GetString("ArgumentCannotBeNullOrEmpy"); => GetString("ArgumentCannotBeNullOrEmpy");
/// <summary>
/// Inject a service from the application's service container into a property.
/// </summary>
internal static string InjectDirective_Description
{
get => GetString("InjectDirective_Description");
}
/// <summary>
/// Inject a service from the application's service container into a property.
/// </summary>
internal static string FormatInjectDirective_Description()
=> GetString("InjectDirective_Description");
/// <summary>
/// The name of the property.
/// </summary>
internal static string InjectDirective_MemberToken_Description
{
get => GetString("InjectDirective_MemberToken_Description");
}
/// <summary>
/// The name of the property.
/// </summary>
internal static string FormatInjectDirective_MemberToken_Description()
=> GetString("InjectDirective_MemberToken_Description");
/// <summary>
/// PropertyName
/// </summary>
internal static string InjectDirective_MemberToken_Name
{
get => GetString("InjectDirective_MemberToken_Name");
}
/// <summary>
/// PropertyName
/// </summary>
internal static string FormatInjectDirective_MemberToken_Name()
=> GetString("InjectDirective_MemberToken_Name");
/// <summary>
/// The type of the service to inject.
/// </summary>
internal static string InjectDirective_TypeToken_Description
{
get => GetString("InjectDirective_TypeToken_Description");
}
/// <summary>
/// The type of the service to inject.
/// </summary>
internal static string FormatInjectDirective_TypeToken_Description()
=> GetString("InjectDirective_TypeToken_Description");
/// <summary>
/// TypeName
/// </summary>
internal static string InjectDirective_TypeToken_Name
{
get => GetString("InjectDirective_TypeToken_Name");
}
/// <summary>
/// TypeName
/// </summary>
internal static string FormatInjectDirective_TypeToken_Name()
=> GetString("InjectDirective_TypeToken_Name");
/// <summary>
/// Specify the view or page model for the page.
/// </summary>
internal static string ModelDirective_Description
{
get => GetString("ModelDirective_Description");
}
/// <summary>
/// Specify the view or page model for the page.
/// </summary>
internal static string FormatModelDirective_Description()
=> GetString("ModelDirective_Description");
/// <summary>
/// The model type.
/// </summary>
internal static string ModelDirective_TypeToken_Description
{
get => GetString("ModelDirective_TypeToken_Description");
}
/// <summary>
/// The model type.
/// </summary>
internal static string FormatModelDirective_TypeToken_Description()
=> GetString("ModelDirective_TypeToken_Description");
/// <summary>
/// TypeName
/// </summary>
internal static string ModelDirective_TypeToken_Name
{
get => GetString("ModelDirective_TypeToken_Name");
}
/// <summary>
/// TypeName
/// </summary>
internal static string FormatModelDirective_TypeToken_Name()
=> GetString("ModelDirective_TypeToken_Name");
/// <summary> /// <summary>
/// The 'inherits' keyword is not allowed when a '{0}' keyword is used. /// The 'inherits' keyword is not allowed when a '{0}' keyword is used.
/// </summary> /// </summary>

View File

@ -120,6 +120,30 @@
<data name="ArgumentCannotBeNullOrEmpy" xml:space="preserve"> <data name="ArgumentCannotBeNullOrEmpy" xml:space="preserve">
<value>Value cannot be null or empty.</value> <value>Value cannot be null or empty.</value>
</data> </data>
<data name="InjectDirective_Description" xml:space="preserve">
<value>Inject a service from the application's service container into a property.</value>
</data>
<data name="InjectDirective_MemberToken_Description" xml:space="preserve">
<value>The name of the property.</value>
</data>
<data name="InjectDirective_MemberToken_Name" xml:space="preserve">
<value>PropertyName</value>
</data>
<data name="InjectDirective_TypeToken_Description" xml:space="preserve">
<value>The type of the service to inject.</value>
</data>
<data name="InjectDirective_TypeToken_Name" xml:space="preserve">
<value>TypeName</value>
</data>
<data name="ModelDirective_Description" xml:space="preserve">
<value>Specify the view or page model for the page.</value>
</data>
<data name="ModelDirective_TypeToken_Description" xml:space="preserve">
<value>The model type.</value>
</data>
<data name="ModelDirective_TypeToken_Name" xml:space="preserve">
<value>TypeName</value>
</data>
<data name="MvcRazorCodeParser_CannotHaveModelAndInheritsKeyword" xml:space="preserve"> <data name="MvcRazorCodeParser_CannotHaveModelAndInheritsKeyword" xml:space="preserve">
<value>The 'inherits' keyword is not allowed when a '{0}' keyword is used.</value> <value>The 'inherits' keyword is not allowed when a '{0}' keyword is used.</value>
</data> </data>

View File

@ -16,7 +16,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddTypeToken().AddMemberToken(); builder
.AddTypeToken(Resources.InjectDirective_TypeToken_Name, Resources.InjectDirective_TypeToken_Description)
.AddMemberToken(Resources.InjectDirective_MemberToken_Name, Resources.InjectDirective_MemberToken_Description);
builder.Usage = DirectiveUsage.FileScopedMultipleOccurring; builder.Usage = DirectiveUsage.FileScopedMultipleOccurring;
builder.Description = Resources.InjectDirective_Description; builder.Description = Resources.InjectDirective_Description;
}); });

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddTypeToken(); builder.AddTypeToken(Resources.ModelDirective_TypeToken_Name, Resources.ModelDirective_TypeToken_Description);
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring; builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
builder.Description = Resources.ModelDirective_Description; builder.Description = Resources.ModelDirective_Description;
}); });

View File

@ -19,7 +19,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddNamespaceToken(); builder.AddNamespaceToken(
Resources.NamespaceDirective_NamespaceToken_Name,
Resources.NamespaceDirective_NamespaceToken_Description);
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring; builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
builder.Description = Resources.NamespaceDirective_Description; builder.Description = Resources.NamespaceDirective_Description;
}); });

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddOptionalStringToken(); builder.AddOptionalStringToken(Resources.PageDirective_RouteToken_Name, Resources.PageDirective_RouteToken_Description);
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring; builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
builder.Description = Resources.PageDirective_Description; builder.Description = Resources.PageDirective_Description;
}); });

View File

@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
=> GetString("ArgumentCannotBeNullOrEmpy"); => GetString("ArgumentCannotBeNullOrEmpy");
/// <summary> /// <summary>
/// Declare a property and inject a service from the application's service container into it. /// Inject a service from the application's service container into a property.
/// </summary> /// </summary>
internal static string InjectDirective_Description internal static string InjectDirective_Description
{ {
@ -33,13 +33,69 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
/// <summary> /// <summary>
/// Declare a property and inject a service from the application's service container into it. /// Inject a service from the application's service container into a property.
/// </summary> /// </summary>
internal static string FormatInjectDirective_Description() internal static string FormatInjectDirective_Description()
=> GetString("InjectDirective_Description"); => GetString("InjectDirective_Description");
/// <summary> /// <summary>
/// Specify the view or page model for the current document. /// The name of the property.
/// </summary>
internal static string InjectDirective_MemberToken_Description
{
get => GetString("InjectDirective_MemberToken_Description");
}
/// <summary>
/// The name of the property.
/// </summary>
internal static string FormatInjectDirective_MemberToken_Description()
=> GetString("InjectDirective_MemberToken_Description");
/// <summary>
/// PropertyName
/// </summary>
internal static string InjectDirective_MemberToken_Name
{
get => GetString("InjectDirective_MemberToken_Name");
}
/// <summary>
/// PropertyName
/// </summary>
internal static string FormatInjectDirective_MemberToken_Name()
=> GetString("InjectDirective_MemberToken_Name");
/// <summary>
/// The type of the service to inject.
/// </summary>
internal static string InjectDirective_TypeToken_Description
{
get => GetString("InjectDirective_TypeToken_Description");
}
/// <summary>
/// The type of the service to inject.
/// </summary>
internal static string FormatInjectDirective_TypeToken_Description()
=> GetString("InjectDirective_TypeToken_Description");
/// <summary>
/// TypeName
/// </summary>
internal static string InjectDirective_TypeToken_Name
{
get => GetString("InjectDirective_TypeToken_Name");
}
/// <summary>
/// TypeName
/// </summary>
internal static string FormatInjectDirective_TypeToken_Name()
=> GetString("InjectDirective_TypeToken_Name");
/// <summary>
/// Specify the view or page model for the page.
/// </summary> /// </summary>
internal static string ModelDirective_Description internal static string ModelDirective_Description
{ {
@ -47,11 +103,39 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
/// <summary> /// <summary>
/// Specify the view or page model for the current document. /// Specify the view or page model for the page.
/// </summary> /// </summary>
internal static string FormatModelDirective_Description() internal static string FormatModelDirective_Description()
=> GetString("ModelDirective_Description"); => GetString("ModelDirective_Description");
/// <summary>
/// The model type.
/// </summary>
internal static string ModelDirective_TypeToken_Description
{
get => GetString("ModelDirective_TypeToken_Description");
}
/// <summary>
/// The model type.
/// </summary>
internal static string FormatModelDirective_TypeToken_Description()
=> GetString("ModelDirective_TypeToken_Description");
/// <summary>
/// TypeName
/// </summary>
internal static string ModelDirective_TypeToken_Name
{
get => GetString("ModelDirective_TypeToken_Name");
}
/// <summary>
/// TypeName
/// </summary>
internal static string FormatModelDirective_TypeToken_Name()
=> GetString("ModelDirective_TypeToken_Name");
/// <summary> /// <summary>
/// The 'inherits' keyword is not allowed when a '{0}' keyword is used. /// The 'inherits' keyword is not allowed when a '{0}' keyword is used.
/// </summary> /// </summary>
@ -123,7 +207,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
=> string.Format(CultureInfo.CurrentCulture, GetString("MvcRazorParser_InvalidPropertyType"), p0, p1, p2); => string.Format(CultureInfo.CurrentCulture, GetString("MvcRazorParser_InvalidPropertyType"), p0, p1, p2);
/// <summary> /// <summary>
/// Specify the base namespace for the current document. /// Specify the base namespace for the page.
/// </summary> /// </summary>
internal static string NamespaceDirective_Description internal static string NamespaceDirective_Description
{ {
@ -131,11 +215,39 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
/// <summary> /// <summary>
/// Specify the base namespace for the current document. /// Specify the base namespace for the page.
/// </summary> /// </summary>
internal static string FormatNamespaceDirective_Description() internal static string FormatNamespaceDirective_Description()
=> GetString("NamespaceDirective_Description"); => GetString("NamespaceDirective_Description");
/// <summary>
/// The namespace for the page.
/// </summary>
internal static string NamespaceDirective_NamespaceToken_Description
{
get => GetString("NamespaceDirective_NamespaceToken_Description");
}
/// <summary>
/// The namespace for the page.
/// </summary>
internal static string FormatNamespaceDirective_NamespaceToken_Description()
=> GetString("NamespaceDirective_NamespaceToken_Description");
/// <summary>
/// Namespace
/// </summary>
internal static string NamespaceDirective_NamespaceToken_Name
{
get => GetString("NamespaceDirective_NamespaceToken_Name");
}
/// <summary>
/// Namespace
/// </summary>
internal static string FormatNamespaceDirective_NamespaceToken_Name()
=> GetString("NamespaceDirective_NamespaceToken_Name");
/// <summary> /// <summary>
/// The '@{0}' directive specified in {1} file will not be imported. The directive must appear at the top of each Razor cshtml file. /// The '@{0}' directive specified in {1} file will not be imported. The directive must appear at the top of each Razor cshtml file.
/// </summary> /// </summary>
@ -151,7 +263,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
=> string.Format(CultureInfo.CurrentCulture, GetString("PageDirectiveCannotBeImported"), p0, p1); => string.Format(CultureInfo.CurrentCulture, GetString("PageDirectiveCannotBeImported"), p0, p1);
/// <summary> /// <summary>
/// Declare the current document as a Razor Page. /// Mark the page as a Razor Page.
/// </summary> /// </summary>
internal static string PageDirective_Description internal static string PageDirective_Description
{ {
@ -159,11 +271,39 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
/// <summary> /// <summary>
/// Declare the current document as a Razor Page. /// Mark the page as a Razor Page.
/// </summary> /// </summary>
internal static string FormatPageDirective_Description() internal static string FormatPageDirective_Description()
=> GetString("PageDirective_Description"); => GetString("PageDirective_Description");
/// <summary>
/// An optional route template for the page.
/// </summary>
internal static string PageDirective_RouteToken_Description
{
get => GetString("PageDirective_RouteToken_Description");
}
/// <summary>
/// An optional route template for the page.
/// </summary>
internal static string FormatPageDirective_RouteToken_Description()
=> GetString("PageDirective_RouteToken_Description");
/// <summary>
/// RouteTemplate
/// </summary>
internal static string PageDirective_RouteToken_Name
{
get => GetString("PageDirective_RouteToken_Name");
}
/// <summary>
/// RouteTemplate
/// </summary>
internal static string FormatPageDirective_RouteToken_Name()
=> GetString("PageDirective_RouteToken_Name");
private static string GetString(string name, params string[] formatterNames) private static string GetString(string name, params string[] formatterNames)
{ {
var value = _resourceManager.GetString(name); var value = _resourceManager.GetString(name);

View File

@ -121,10 +121,28 @@
<value>Value cannot be null or empty.</value> <value>Value cannot be null or empty.</value>
</data> </data>
<data name="InjectDirective_Description" xml:space="preserve"> <data name="InjectDirective_Description" xml:space="preserve">
<value>Declare a property and inject a service from the application's service container into it.</value> <value>Inject a service from the application's service container into a property.</value>
</data>
<data name="InjectDirective_MemberToken_Description" xml:space="preserve">
<value>The name of the property.</value>
</data>
<data name="InjectDirective_MemberToken_Name" xml:space="preserve">
<value>PropertyName</value>
</data>
<data name="InjectDirective_TypeToken_Description" xml:space="preserve">
<value>The type of the service to inject.</value>
</data>
<data name="InjectDirective_TypeToken_Name" xml:space="preserve">
<value>TypeName</value>
</data> </data>
<data name="ModelDirective_Description" xml:space="preserve"> <data name="ModelDirective_Description" xml:space="preserve">
<value>Specify the view or page model for the current document.</value> <value>Specify the view or page model for the page.</value>
</data>
<data name="ModelDirective_TypeToken_Description" xml:space="preserve">
<value>The model type.</value>
</data>
<data name="ModelDirective_TypeToken_Name" xml:space="preserve">
<value>TypeName</value>
</data> </data>
<data name="MvcRazorCodeParser_CannotHaveModelAndInheritsKeyword" xml:space="preserve"> <data name="MvcRazorCodeParser_CannotHaveModelAndInheritsKeyword" xml:space="preserve">
<value>The 'inherits' keyword is not allowed when a '{0}' keyword is used.</value> <value>The 'inherits' keyword is not allowed when a '{0}' keyword is used.</value>
@ -142,12 +160,24 @@
<value>Invalid tag helper property '{0}.{1}'. Dictionary values must not be of type '{2}'.</value> <value>Invalid tag helper property '{0}.{1}'. Dictionary values must not be of type '{2}'.</value>
</data> </data>
<data name="NamespaceDirective_Description" xml:space="preserve"> <data name="NamespaceDirective_Description" xml:space="preserve">
<value>Specify the base namespace for the current document.</value> <value>Specify the base namespace for the page.</value>
</data>
<data name="NamespaceDirective_NamespaceToken_Description" xml:space="preserve">
<value>The namespace for the page.</value>
</data>
<data name="NamespaceDirective_NamespaceToken_Name" xml:space="preserve">
<value>Namespace</value>
</data> </data>
<data name="PageDirectiveCannotBeImported" xml:space="preserve"> <data name="PageDirectiveCannotBeImported" xml:space="preserve">
<value>The '@{0}' directive specified in {1} file will not be imported. The directive must appear at the top of each Razor cshtml file.</value> <value>The '@{0}' directive specified in {1} file will not be imported. The directive must appear at the top of each Razor cshtml file.</value>
</data> </data>
<data name="PageDirective_Description" xml:space="preserve"> <data name="PageDirective_Description" xml:space="preserve">
<value>Declare the current document as a Razor Page.</value> <value>Mark the page as a Razor Page.</value>
</data>
<data name="PageDirective_RouteToken_Description" xml:space="preserve">
<value>An optional route template for the page.</value>
</data>
<data name="PageDirective_RouteToken_Name" xml:space="preserve">
<value>RouteTemplate</value>
</data> </data>
</root> </root>

View File

@ -8,90 +8,178 @@ namespace Microsoft.AspNetCore.Razor.Language
public static class DirectiveDescriptorBuilderExtensions public static class DirectiveDescriptorBuilderExtensions
{ {
public static IDirectiveDescriptorBuilder AddMemberToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddMemberToken(this IDirectiveDescriptorBuilder builder)
{
return AddMemberToken(builder, name: null, description: null);
}
public static IDirectiveDescriptorBuilder AddMemberToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Member)); builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.Member,
optional: false,
name: name,
description: description));
return builder; return builder;
} }
public static IDirectiveDescriptorBuilder AddNamespaceToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddNamespaceToken(this IDirectiveDescriptorBuilder builder)
{
return AddNamespaceToken(builder, name: null, description: null);
}
public static IDirectiveDescriptorBuilder AddNamespaceToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Namespace)); builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.Namespace,
optional: false,
name: name,
description: description));
return builder; return builder;
} }
public static IDirectiveDescriptorBuilder AddStringToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddStringToken(this IDirectiveDescriptorBuilder builder)
{
return AddStringToken(builder, name: null, description: null);
}
public static IDirectiveDescriptorBuilder AddStringToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.String)); builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.String,
optional: false,
name: name,
description: description));
return builder; return builder;
} }
public static IDirectiveDescriptorBuilder AddTypeToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddTypeToken(this IDirectiveDescriptorBuilder builder)
{
return AddTypeToken(builder, name: null, description: null);
}
public static IDirectiveDescriptorBuilder AddTypeToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Type)); builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.Type,
optional: false,
name: name,
description: description));
return builder; return builder;
} }
public static IDirectiveDescriptorBuilder AddOptionalMemberToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddOptionalMemberToken(this IDirectiveDescriptorBuilder builder)
{
return AddOptionalMemberToken(builder, name: null, description: null);
}
public static IDirectiveDescriptorBuilder AddOptionalMemberToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Member, optional: true)); builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.Member,
optional: true,
name: name,
description: description));
return builder; return builder;
} }
public static IDirectiveDescriptorBuilder AddOptionalNamespaceToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddOptionalNamespaceToken(this IDirectiveDescriptorBuilder builder)
{
return AddOptionalNamespaceToken(builder, name: null, description: null);
}
public static IDirectiveDescriptorBuilder AddOptionalNamespaceToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Namespace, optional: true)); builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.Namespace,
optional: true,
name: name,
description: description));
return builder; return builder;
} }
public static IDirectiveDescriptorBuilder AddOptionalStringToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddOptionalStringToken(this IDirectiveDescriptorBuilder builder)
{ {
if (builder == null) return AddOptionalStringToken(builder, name: null, description: null);
{
throw new ArgumentNullException(nameof(builder));
}
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.String, optional: true));
return builder;
} }
public static IDirectiveDescriptorBuilder AddOptionalTypeToken(this IDirectiveDescriptorBuilder builder) public static IDirectiveDescriptorBuilder AddOptionalStringToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }
builder.Tokens.Add(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Type, optional: true)); builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.String,
optional: true,
name: name,
description: description));
return builder;
}
public static IDirectiveDescriptorBuilder AddOptionalTypeToken(this IDirectiveDescriptorBuilder builder)
{
return AddOptionalTypeToken(builder, name: null, description: null);
}
public static IDirectiveDescriptorBuilder AddOptionalTypeToken(this IDirectiveDescriptorBuilder builder, string name, string description)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.Tokens.Add(
DirectiveTokenDescriptor.CreateToken(
DirectiveTokenKind.Type,
optional: true,
name: name,
description: description));
return builder; return builder;
} }
} }

View File

@ -9,6 +9,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public abstract bool Optional { get; } public abstract bool Optional { get; }
public virtual string Name { get; }
public virtual string Description { get; }
public static DirectiveTokenDescriptor CreateToken(DirectiveTokenKind kind) public static DirectiveTokenDescriptor CreateToken(DirectiveTokenKind kind)
{ {
return CreateToken(kind, optional: false); return CreateToken(kind, optional: false);
@ -16,20 +20,31 @@ namespace Microsoft.AspNetCore.Razor.Language
public static DirectiveTokenDescriptor CreateToken(DirectiveTokenKind kind, bool optional) public static DirectiveTokenDescriptor CreateToken(DirectiveTokenKind kind, bool optional)
{ {
return new DefaultDirectiveTokenDescriptor(kind, optional); return CreateToken(kind, optional, name: null, description: null);
}
public static DirectiveTokenDescriptor CreateToken(DirectiveTokenKind kind, bool optional, string name, string description)
{
return new DefaultDirectiveTokenDescriptor(kind, optional, name, description);
} }
private class DefaultDirectiveTokenDescriptor : DirectiveTokenDescriptor private class DefaultDirectiveTokenDescriptor : DirectiveTokenDescriptor
{ {
public DefaultDirectiveTokenDescriptor(DirectiveTokenKind kind, bool optional) public DefaultDirectiveTokenDescriptor(DirectiveTokenKind kind, bool optional, string name, string description)
{ {
Kind = kind; Kind = kind;
Optional = optional; Optional = optional;
Name = name;
Description = description;
} }
public override DirectiveTokenKind Kind { get; } public override DirectiveTokenKind Kind { get; }
public override bool Optional { get; } public override bool Optional { get; }
public override string Name { get; }
public override string Description { get; }
} }
} }
} }

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddTypeToken(); builder.AddTypeToken(Resources.InheritsDirective_TypeToken_Name, Resources.InheritsDirective_TypeToken_Description);
builder.Usage = DirectiveUsage.FileScopedSinglyOccurring; builder.Usage = DirectiveUsage.FileScopedSinglyOccurring;
builder.Description = Resources.InheritsDirective_Description; builder.Description = Resources.InheritsDirective_Description;
}); });

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
DirectiveKind.RazorBlock, DirectiveKind.RazorBlock,
builder => builder =>
{ {
builder.AddMemberToken(); builder.AddMemberToken(Resources.SectionDirective_NameToken_Name, Resources.SectionDirective_NameToken_Description);
builder.Description = Resources.SectionDirective_Description; builder.Description = Resources.SectionDirective_Description;
}); });

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddStringToken(); builder.AddStringToken(Resources.AddTagHelperDirective_StringToken_Name, Resources.AddTagHelperDirective_StringToken_Description);
builder.Description = Resources.AddTagHelperDirective_Description; builder.Description = Resources.AddTagHelperDirective_Description;
}); });
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddStringToken(); builder.AddStringToken(Resources.RemoveTagHelperDirective_StringToken_Name, Resources.RemoveTagHelperDirective_StringToken_Description);
builder.Description = Resources.RemoveTagHelperDirective_Description; builder.Description = Resources.RemoveTagHelperDirective_Description;
}); });
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
DirectiveKind.SingleLine, DirectiveKind.SingleLine,
builder => builder =>
{ {
builder.AddStringToken(); builder.AddStringToken(Resources.TagHelperPrefixDirective_PrefixToken_Name, Resources.TagHelperPrefixDirective_PrefixToken_Description);
builder.Description = Resources.TagHelperPrefixDirective_Description; builder.Description = Resources.TagHelperPrefixDirective_Description;
}); });

View File

@ -696,6 +696,146 @@ namespace Microsoft.AspNetCore.Razor.Language
internal static string FormatInvalidRazorLanguageVersion(object p0) internal static string FormatInvalidRazorLanguageVersion(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("InvalidRazorLanguageVersion"), p0); => string.Format(CultureInfo.CurrentCulture, GetString("InvalidRazorLanguageVersion"), p0);
/// <summary>
/// Add tag helpers from the specified type name and assembly name. Specify '*' for the type name to include all tag helper types from the specified assembly.
/// </summary>
internal static string AddTagHelperDirective_StringToken_Description
{
get => GetString("AddTagHelperDirective_StringToken_Description");
}
/// <summary>
/// Add tag helpers from the specified type name and assembly name. Specify '*' for the type name to include all tag helper types from the specified assembly.
/// </summary>
internal static string FormatAddTagHelperDirective_StringToken_Description()
=> GetString("AddTagHelperDirective_StringToken_Description");
/// <summary>
/// TypeName, AssemblyName
/// </summary>
internal static string AddTagHelperDirective_StringToken_Name
{
get => GetString("AddTagHelperDirective_StringToken_Name");
}
/// <summary>
/// TypeName, AssemblyName
/// </summary>
internal static string FormatAddTagHelperDirective_StringToken_Name()
=> GetString("AddTagHelperDirective_StringToken_Name");
/// <summary>
/// The base type that the current page inherits.
/// </summary>
internal static string InheritsDirective_TypeToken_Description
{
get => GetString("InheritsDirective_TypeToken_Description");
}
/// <summary>
/// The base type that the current page inherits.
/// </summary>
internal static string FormatInheritsDirective_TypeToken_Description()
=> GetString("InheritsDirective_TypeToken_Description");
/// <summary>
/// TypeName
/// </summary>
internal static string InheritsDirective_TypeToken_Name
{
get => GetString("InheritsDirective_TypeToken_Name");
}
/// <summary>
/// TypeName
/// </summary>
internal static string FormatInheritsDirective_TypeToken_Name()
=> GetString("InheritsDirective_TypeToken_Name");
/// <summary>
/// Remove tag helpers from the specified type name and assembly name. Specify '*' for the type name to remove all tag helper types from the specified assembly.
/// </summary>
internal static string RemoveTagHelperDirective_StringToken_Description
{
get => GetString("RemoveTagHelperDirective_StringToken_Description");
}
/// <summary>
/// Remove tag helpers from the specified type name and assembly name. Specify '*' for the type name to remove all tag helper types from the specified assembly.
/// </summary>
internal static string FormatRemoveTagHelperDirective_StringToken_Description()
=> GetString("RemoveTagHelperDirective_StringToken_Description");
/// <summary>
/// TypeName, AssemblyName
/// </summary>
internal static string RemoveTagHelperDirective_StringToken_Name
{
get => GetString("RemoveTagHelperDirective_StringToken_Name");
}
/// <summary>
/// TypeName, AssemblyName
/// </summary>
internal static string FormatRemoveTagHelperDirective_StringToken_Name()
=> GetString("RemoveTagHelperDirective_StringToken_Name");
/// <summary>
/// The tag prefix to apply to tag helpers.
/// </summary>
internal static string TagHelperPrefixDirective_PrefixToken_Description
{
get => GetString("TagHelperPrefixDirective_PrefixToken_Description");
}
/// <summary>
/// The tag prefix to apply to tag helpers.
/// </summary>
internal static string FormatTagHelperPrefixDirective_PrefixToken_Description()
=> GetString("TagHelperPrefixDirective_PrefixToken_Description");
/// <summary>
/// Prefix
/// </summary>
internal static string TagHelperPrefixDirective_PrefixToken_Name
{
get => GetString("TagHelperPrefixDirective_PrefixToken_Name");
}
/// <summary>
/// Prefix
/// </summary>
internal static string FormatTagHelperPrefixDirective_PrefixToken_Name()
=> GetString("TagHelperPrefixDirective_PrefixToken_Name");
/// <summary>
/// The name of the section.
/// </summary>
internal static string SectionDirective_NameToken_Description
{
get => GetString("SectionDirective_NameToken_Description");
}
/// <summary>
/// The name of the section.
/// </summary>
internal static string FormatSectionDirective_NameToken_Description()
=> GetString("SectionDirective_NameToken_Description");
/// <summary>
/// SectionName
/// </summary>
internal static string SectionDirective_NameToken_Name
{
get => GetString("SectionDirective_NameToken_Name");
}
/// <summary>
/// SectionName
/// </summary>
internal static string FormatSectionDirective_NameToken_Name()
=> GetString("SectionDirective_NameToken_Name");
private static string GetString(string name, params string[] formatterNames) private static string GetString(string name, params string[] formatterNames)
{ {
var value = _resourceManager.GetString(name); var value = _resourceManager.GetString(name);

View File

@ -264,4 +264,34 @@
<data name="InvalidRazorLanguageVersion" xml:space="preserve"> <data name="InvalidRazorLanguageVersion" xml:space="preserve">
<value>Provided value for razor language version is unsupported or invalid: '{0}'.</value> <value>Provided value for razor language version is unsupported or invalid: '{0}'.</value>
</data> </data>
<data name="AddTagHelperDirective_StringToken_Description" xml:space="preserve">
<value>Add tag helpers from the specified type name and assembly name. Specify '*' for the type name to include all tag helper types from the specified assembly.</value>
</data>
<data name="AddTagHelperDirective_StringToken_Name" xml:space="preserve">
<value>TypeName, AssemblyName</value>
</data>
<data name="InheritsDirective_TypeToken_Description" xml:space="preserve">
<value>The base type that the current page inherits.</value>
</data>
<data name="InheritsDirective_TypeToken_Name" xml:space="preserve">
<value>TypeName</value>
</data>
<data name="RemoveTagHelperDirective_StringToken_Description" xml:space="preserve">
<value>Remove tag helpers from the specified type name and assembly name. Specify '*' for the type name to remove all tag helper types from the specified assembly.</value>
</data>
<data name="RemoveTagHelperDirective_StringToken_Name" xml:space="preserve">
<value>TypeName, AssemblyName</value>
</data>
<data name="TagHelperPrefixDirective_PrefixToken_Description" xml:space="preserve">
<value>The tag prefix to apply to tag helpers.</value>
</data>
<data name="TagHelperPrefixDirective_PrefixToken_Name" xml:space="preserve">
<value>Prefix</value>
</data>
<data name="SectionDirective_NameToken_Description" xml:space="preserve">
<value>The name of the section.</value>
</data>
<data name="SectionDirective_NameToken_Name" xml:space="preserve">
<value>SectionName</value>
</data>
</root> </root>

View File

@ -17,18 +17,22 @@ namespace Microsoft.AspNetCore.Razor.Language
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.Member, token.Kind); Assert.Equal(DirectiveTokenKind.Member, token.Kind);
Assert.False(token.Optional); Assert.False(token.Optional);
Assert.Null(token.Name);
Assert.Null(token.Description);
} }
[Fact] [Fact]
public void AddNamespaceToken_AddsToken() public void AddNamespaceToken_AddsToken()
{ {
// Arrange & Act // Arrange & Act
var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddNamespaceToken()); var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddNamespaceToken("Name", "Description"));
// Assert // Assert
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.Namespace, token.Kind); Assert.Equal(DirectiveTokenKind.Namespace, token.Kind);
Assert.False(token.Optional); Assert.False(token.Optional);
Assert.Equal("Name", token.Name);
Assert.Equal("Description", token.Description);
} }
[Fact] [Fact]
@ -41,18 +45,22 @@ namespace Microsoft.AspNetCore.Razor.Language
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.String, token.Kind); Assert.Equal(DirectiveTokenKind.String, token.Kind);
Assert.False(token.Optional); Assert.False(token.Optional);
Assert.Null(token.Name);
Assert.Null(token.Description);
} }
[Fact] [Fact]
public void AddTypeToken_AddsToken() public void AddTypeToken_AddsToken()
{ {
// Arrange & Act // Arrange & Act
var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddTypeToken()); var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddTypeToken("Name", "Description"));
// Assert // Assert
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.Type, token.Kind); Assert.Equal(DirectiveTokenKind.Type, token.Kind);
Assert.False(token.Optional); Assert.False(token.Optional);
Assert.Equal("Name", token.Name);
Assert.Equal("Description", token.Description);
} }
[Fact] [Fact]
@ -65,18 +73,22 @@ namespace Microsoft.AspNetCore.Razor.Language
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.Type, token.Kind); Assert.Equal(DirectiveTokenKind.Type, token.Kind);
Assert.True(token.Optional); Assert.True(token.Optional);
Assert.Null(token.Name);
Assert.Null(token.Description);
} }
[Fact] [Fact]
public void AddOptionalMemberToken_AddsToken() public void AddOptionalMemberToken_AddsToken()
{ {
// Arrange & Act // Arrange & Act
var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddOptionalMemberToken()); var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddOptionalMemberToken("Name", "Description"));
// Assert // Assert
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.Member, token.Kind); Assert.Equal(DirectiveTokenKind.Member, token.Kind);
Assert.True(token.Optional); Assert.True(token.Optional);
Assert.Equal("Name", token.Name);
Assert.Equal("Description", token.Description);
} }
[Fact] [Fact]
@ -89,18 +101,22 @@ namespace Microsoft.AspNetCore.Razor.Language
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.Namespace, token.Kind); Assert.Equal(DirectiveTokenKind.Namespace, token.Kind);
Assert.True(token.Optional); Assert.True(token.Optional);
Assert.Null(token.Name);
Assert.Null(token.Description);
} }
[Fact] [Fact]
public void AddOptionalStringToken_AddsToken() public void AddOptionalStringToken_AddsToken()
{ {
// Arrange & Act // Arrange & Act
var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddOptionalStringToken()); var descriptor = DirectiveDescriptor.CreateDirective("custom", DirectiveKind.SingleLine, b => b.AddOptionalStringToken("Name", "Description"));
// Assert // Assert
var token = Assert.Single(descriptor.Tokens); var token = Assert.Single(descriptor.Tokens);
Assert.Equal(DirectiveTokenKind.String, token.Kind); Assert.Equal(DirectiveTokenKind.String, token.Kind);
Assert.True(token.Optional); Assert.True(token.Optional);
Assert.Equal("Name", token.Name);
Assert.Equal("Description", token.Description);
} }
} }
} }