Skip to content

C#: Include AttributeUsages in stub generator #14609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2023
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 @@ -186,7 +186,8 @@ private void StubTypedConstant(TypedConstant c)
}
break;
case TypedConstantKind.Enum:
stubWriter.Write("throw null");
stubWriter.Write($"({c.Type!.GetQualifiedName()}) ");
stubWriter.Write(c.Value!.ToString());
break;
case TypedConstantKind.Array:
stubWriter.Write("new []{");
Expand All @@ -200,7 +201,8 @@ private void StubTypedConstant(TypedConstant c)
}

private static readonly HashSet<string> attributeAllowList = new() {
"System.FlagsAttribute"
"System.FlagsAttribute",
"System.AttributeUsageAttribute"
};

private void StubAttribute(AttributeData a, string prefix)
Expand All @@ -219,6 +221,14 @@ private void StubAttribute(AttributeData a, string prefix)
{
stubWriter.Write("(");
WriteCommaSep(a.ConstructorArguments, StubTypedConstant);
if (a.ConstructorArguments.Any() && a.NamedArguments.Any())
stubWriter.Write(",");
WriteCommaSep(a.NamedArguments, arg =>
{
stubWriter.Write(arg.Key);
stubWriter.Write(" = ");
StubTypedConstant(arg.Value);
});
stubWriter.Write(")");
}
stubWriter.WriteLine("]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace AspNetCore
{
namespace Authorization
{
[System.AttributeUsage((System.AttributeTargets)68, AllowMultiple = false, Inherited = true)]
public class AllowAnonymousAttribute : System.Attribute, Microsoft.AspNetCore.Authorization.IAllowAnonymous
{
public AllowAnonymousAttribute() => throw null;
Expand Down Expand Up @@ -120,6 +121,7 @@ public static partial class AuthorizationServiceExtensions
public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Authorization.AuthorizationResult> AuthorizeAsync(this Microsoft.AspNetCore.Authorization.IAuthorizationService service, System.Security.Claims.ClaimsPrincipal user, Microsoft.AspNetCore.Authorization.AuthorizationPolicy policy) => throw null;
public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Authorization.AuthorizationResult> AuthorizeAsync(this Microsoft.AspNetCore.Authorization.IAuthorizationService service, System.Security.Claims.ClaimsPrincipal user, string policyName) => throw null;
}
[System.AttributeUsage((System.AttributeTargets)68, AllowMultiple = true, Inherited = true)]
public class AuthorizeAttribute : System.Attribute, Microsoft.AspNetCore.Authorization.IAuthorizeData
{
public string AuthenticationSchemes { get => throw null; set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace AspNetCore
{
namespace Components
{
[System.AttributeUsage((System.AttributeTargets)4, AllowMultiple = true, Inherited = true)]
public sealed class BindInputElementAttribute : System.Attribute
{
public string ChangeAttribute { get => throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static class BindConverter
public static bool TryConvertToTimeOnly(object obj, System.Globalization.CultureInfo culture, out System.TimeOnly value) => throw null;
public static bool TryConvertToTimeOnly(object obj, System.Globalization.CultureInfo culture, string format, out System.TimeOnly value) => throw null;
}
[System.AttributeUsage((System.AttributeTargets)4, AllowMultiple = true, Inherited = true)]
public sealed class BindElementAttribute : System.Attribute
{
public string ChangeAttribute { get => throw null; }
Expand All @@ -81,11 +82,13 @@ public sealed class BindElementAttribute : System.Attribute
public string Suffix { get => throw null; }
public string ValueAttribute { get => throw null; }
}
[System.AttributeUsage((System.AttributeTargets)128, AllowMultiple = false, Inherited = true)]
public sealed class CascadingParameterAttribute : System.Attribute
{
public CascadingParameterAttribute() => throw null;
public string Name { get => throw null; set { } }
}
[System.AttributeUsage((System.AttributeTargets)4, AllowMultiple = true, Inherited = false)]
public sealed class CascadingTypeParameterAttribute : System.Attribute
{
public CascadingTypeParameterAttribute(string name) => throw null;
Expand Down Expand Up @@ -161,6 +164,7 @@ public class DynamicComponent : Microsoft.AspNetCore.Components.IComponent
public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) => throw null;
public System.Type Type { get => throw null; set { } }
}
[System.AttributeUsage((System.AttributeTargets)128, AllowMultiple = false)]
public sealed class EditorRequiredAttribute : System.Attribute
{
public EditorRequiredAttribute() => throw null;
Expand Down Expand Up @@ -300,6 +304,7 @@ public struct EventCallbackWorkItem
public static readonly Microsoft.AspNetCore.Components.EventCallbackWorkItem Empty;
public System.Threading.Tasks.Task InvokeAsync(object arg) => throw null;
}
[System.AttributeUsage((System.AttributeTargets)4, AllowMultiple = true, Inherited = true)]
public sealed class EventHandlerAttribute : System.Attribute
{
public string AttributeName { get => throw null; }
Expand Down Expand Up @@ -336,6 +341,7 @@ public class ComponentStatePersistenceManager
public Microsoft.AspNetCore.Components.PersistentComponentState State { get => throw null; }
}
}
[System.AttributeUsage((System.AttributeTargets)128, AllowMultiple = false, Inherited = true)]
public sealed class InjectAttribute : System.Attribute
{
public InjectAttribute() => throw null;
Expand All @@ -345,6 +351,7 @@ public interface IPersistentComponentStateStore
System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string, byte[]>> GetPersistedStateAsync();
System.Threading.Tasks.Task PersistStateAsync(System.Collections.Generic.IReadOnlyDictionary<string, byte[]> state);
}
[System.AttributeUsage((System.AttributeTargets)4, AllowMultiple = false, Inherited = true)]
public sealed class LayoutAttribute : System.Attribute
{
public LayoutAttribute(System.Type layoutType) => throw null;
Expand Down Expand Up @@ -447,6 +454,7 @@ public abstract class OwningComponentBase<TService> : Microsoft.AspNetCore.Compo
protected OwningComponentBase() => throw null;
protected TService Service { get => throw null; }
}
[System.AttributeUsage((System.AttributeTargets)128, AllowMultiple = false, Inherited = true)]
public sealed class ParameterAttribute : System.Attribute
{
public bool CaptureUnmatchedValues { get => throw null; set { } }
Expand Down Expand Up @@ -647,6 +655,7 @@ public enum RenderTreeFrameType : short
Markup = 8,
}
}
[System.AttributeUsage((System.AttributeTargets)4, AllowMultiple = true, Inherited = false)]
public sealed class RouteAttribute : System.Attribute
{
public RouteAttribute(string template) => throw null;
Expand Down Expand Up @@ -714,6 +723,7 @@ public class Router : Microsoft.AspNetCore.Components.IComponent, System.IDispos
public System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) => throw null;
}
}
[System.AttributeUsage((System.AttributeTargets)128, AllowMultiple = false, Inherited = true)]
public sealed class SupplyParameterFromQueryAttribute : System.Attribute
{
public SupplyParameterFromQueryAttribute() => throw null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public class CorsPolicyMetadata : Microsoft.AspNetCore.Cors.Infrastructure.ICors
public CorsPolicyMetadata(Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicy policy) => throw null;
public Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicy Policy { get => throw null; }
}
[System.AttributeUsage((System.AttributeTargets)68, AllowMultiple = false, Inherited = false)]
public class DisableCorsAttribute : System.Attribute, Microsoft.AspNetCore.Cors.Infrastructure.ICorsMetadata, Microsoft.AspNetCore.Cors.Infrastructure.IDisableCorsAttribute
{
public DisableCorsAttribute() => throw null;
}
[System.AttributeUsage((System.AttributeTargets)68, AllowMultiple = false, Inherited = true)]
public class EnableCorsAttribute : System.Attribute, Microsoft.AspNetCore.Cors.Infrastructure.ICorsMetadata, Microsoft.AspNetCore.Cors.Infrastructure.IEnableCorsAttribute
{
public EnableCorsAttribute() => throw null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static partial class HostingEnvironmentExtensions
public static bool IsProduction(this Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment) => throw null;
public static bool IsStaging(this Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment) => throw null;
}
[System.AttributeUsage((System.AttributeTargets)1, Inherited = false, AllowMultiple = true)]
public sealed class HostingStartupAttribute : System.Attribute
{
public HostingStartupAttribute(System.Type hostingStartupType) => throw null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public interface ICorsMetadata
}
namespace Http
{
[System.AttributeUsage((System.AttributeTargets)2048, Inherited = false, AllowMultiple = false)]
public sealed class AsParametersAttribute : System.Attribute
{
public AsParametersAttribute() => throw null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ namespace AspNetCore
{
namespace Http
{
[System.AttributeUsage((System.AttributeTargets)64, Inherited = false, AllowMultiple = false)]
public sealed class EndpointDescriptionAttribute : System.Attribute, Microsoft.AspNetCore.Http.Metadata.IEndpointDescriptionMetadata
{
public EndpointDescriptionAttribute(string description) => throw null;
public string Description { get => throw null; }
}
[System.AttributeUsage((System.AttributeTargets)64, Inherited = false, AllowMultiple = false)]
public sealed class EndpointSummaryAttribute : System.Attribute, Microsoft.AspNetCore.Http.Metadata.IEndpointSummaryMetadata
{
public EndpointSummaryAttribute(string summary) => throw null;
Expand Down Expand Up @@ -195,6 +197,7 @@ public static partial class SessionExtensions
public static void SetInt32(this Microsoft.AspNetCore.Http.ISession session, string key, int value) => throw null;
public static void SetString(this Microsoft.AspNetCore.Http.ISession session, string key, string value) => throw null;
}
[System.AttributeUsage((System.AttributeTargets)4164, Inherited = false, AllowMultiple = false)]
public sealed class TagsAttribute : System.Attribute, Microsoft.AspNetCore.Http.Metadata.ITagsMetadata
{
public TagsAttribute(params string[] tags) => throw null;
Expand Down
Loading