Skip to content

Commit

Permalink
fix: OfType analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
ronimizy committed Nov 11, 2023
1 parent 2ad65d3 commit ac97bca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ private void HandleOperation(OperationAnalysisContext context)
if (returnElementType.IsAssignableTo(sourceElementType))
return;

if (sourceElementType is ITypeParameterSymbol parameterSymbol &&
parameterSymbol.ConstraintTypes.Any(c => returnElementType.IsAssignableTo(c)))
{
return;
}

var diagnostic = Diagnostic.Create(
Descriptor,
operation.Syntax.GetLocation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,30 @@

<PropertyGroup>
<Version>1.0.$(PatchVersion)</Version>
<PackageReleaseNotes>Added OfType analyzer</PackageReleaseNotes>
<PackageReleaseNotes>
Added generic constraint support for OfType analyzer
</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\..\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\..\LICENSE.md" Pack="true" PackagePath="\" />
<None Include="..\..\..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\..\..\LICENSE.md" Pack="true" PackagePath="\"/>
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\..\SourceKit\SourceKit.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\SourceKit\SourceKit.csproj" PrivateAssets="all"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" PrivateAssets="all"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all"/>
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" PrivateAssets="all"/>
</ItemGroup>

<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\SourceKit.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
<None Include="$(OutputPath)\SourceKit.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
</ItemGroup>

</Project>

0 comments on commit ac97bca

Please sign in to comment.