Skip to content
Draft
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
6 changes: 6 additions & 0 deletions src/Components/Analyzers/src/ComponentSymbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public static bool TryCreate(Compilation compilation, out ComponentSymbols symbo
// Try to get optional symbols for SupplyParameterFromForm analyzer
var supplyParameterFromFormAttribute = compilation.GetTypeByMetadataName(ComponentsApi.SupplyParameterFromFormAttribute.MetadataName);
var componentBaseType = compilation.GetTypeByMetadataName(ComponentsApi.ComponentBase.MetadataName);
var elementReferenceType = compilation.GetTypeByMetadataName(ComponentsApi.ElementReference.MetadataName);

symbols = new ComponentSymbols(
parameterAttribute,
cascadingParameterAttribute,
supplyParameterFromFormAttribute,
componentBaseType,
elementReferenceType,
parameterCaptureUnmatchedValuesRuntimeType,
icomponentType);
return true;
Expand All @@ -66,13 +68,15 @@ private ComponentSymbols(
INamedTypeSymbol cascadingParameterAttribute,
INamedTypeSymbol supplyParameterFromFormAttribute,
INamedTypeSymbol componentBaseType,
INamedTypeSymbol elementReferenceType,
INamedTypeSymbol parameterCaptureUnmatchedValuesRuntimeType,
INamedTypeSymbol icomponentType)
{
ParameterAttribute = parameterAttribute;
CascadingParameterAttribute = cascadingParameterAttribute;
SupplyParameterFromFormAttribute = supplyParameterFromFormAttribute; // Can be null
ComponentBaseType = componentBaseType; // Can be null
ElementReferenceType = elementReferenceType; // Can be null
ParameterCaptureUnmatchedValuesRuntimeType = parameterCaptureUnmatchedValuesRuntimeType;
IComponentType = icomponentType;
}
Expand All @@ -88,5 +92,7 @@ private ComponentSymbols(

public INamedTypeSymbol ComponentBaseType { get; } // Can be null if not available

public INamedTypeSymbol ElementReferenceType { get; } // Can be null if not available

public INamedTypeSymbol IComponentType { get; }
}
6 changes: 6 additions & 0 deletions src/Components/Analyzers/src/ComponentsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ public static class IComponent
public const string FullTypeName = "Microsoft.AspNetCore.Components.IComponent";
public const string MetadataName = FullTypeName;
}

public static class ElementReference
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.ElementReference";
public const string MetadataName = FullTypeName;
}
}
18 changes: 18 additions & 0 deletions src/Components/Analyzers/src/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,22 @@ internal static class DiagnosticDescriptors
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: CreateLocalizableResourceString(nameof(Resources.SupplyParameterFromFormShouldNotHavePropertyInitializer_Description)));

public static readonly DiagnosticDescriptor ElementReferenceShouldOnlyBeAccessedInOnAfterRenderAsync = new(
"BL0009",
CreateLocalizableResourceString(nameof(Resources.ElementReferenceShouldOnlyBeAccessedInOnAfterRenderAsync_Title)),
CreateLocalizableResourceString(nameof(Resources.ElementReferenceShouldOnlyBeAccessedInOnAfterRenderAsync_Format)),
Usage,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: CreateLocalizableResourceString(nameof(Resources.ElementReferenceShouldOnlyBeAccessedInOnAfterRenderAsync_Description)));

public static readonly DiagnosticDescriptor ElementReferenceUsageInMethodCalledOutsideOnAfterRender = new(
"BL0010",
CreateLocalizableResourceString(nameof(Resources.ElementReferenceUsageInMethodCalledOutsideOnAfterRender_Title)),
CreateLocalizableResourceString(nameof(Resources.ElementReferenceUsageInMethodCalledOutsideOnAfterRender_Format)),
Usage,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: CreateLocalizableResourceString(nameof(Resources.ElementReferenceUsageInMethodCalledOutsideOnAfterRender_Description)));
}
Loading
Loading