Roslyn: Expose IsByRefLikeType on INameTypeSymbol

Created on 10 Oct 2018  路  4Comments  路  Source: dotnet/roslyn

Useful information that I don't know how to dig out using existing API.

Area-Compilers Bug

All 4 comments

Use case is in https://github.com/DotNetAnalyzers/ReflectionAnalyzers where we want to check:

typeof(C<>).MakeGenericType(typeof(RefStruct));

class C<T>
{
}

That use case doesn't seem to have any ref-structs. Nor does it explain why it's important to know if it's a ref-struct.

The goal of the analyzer is to produce warnings when MakeGenericType is called with illegal type parameters that would be runtime errors. I just checked and this call does not throw at runtime so it is not a good example for motivation :)

MakeGenericType does throw when called with Span<Foo>.

Was this page helpful?
0 / 5 - 0 ratings