Add an API to discover if a symbol is a WellKnownType that effects public API behavior
Background and Motivation
When writing tools that examine an assembly for compatibility, or for public API - it's important to know what's relevant.
There are many types that are "known" by the compiler and used to effect the behavior of API - even when those are not public in the assembly.
It would be nice if the compiler exposed an API that listed these known types so that we wouldn't need to consider them ourselves.
Related https://github.com/dotnet/roslyn/issues/68968
Proposed API
namespace Microsoft.CodeAnalysis
{
public static class WellKnownTypes
{
// returns true if the compiler will treat this type as a well known type that impacts language behavior
public static bool IsWellKnownType(ISymbol symbol)
}
Usage Examples
// returns true if the symbol is meaningful to public API
public bool ShouldIncludeSymbol(ISymbol symbol)
{
return symbol.IsVisible(_visibilitySettings) || WellKnownTypes.IsWellKnownType(symbol);
}
Alternative Designs
We can maintain a static list ourselves - or ask users to specify - but it's error prone and incomplete. The compiler knows which symbols it allows to be defined in user assemblies to augment its behavior - it would d be nice if that was exposed to callers.
Risks
Potentially some performance risk - though this could be implemented entirely on the side.
@333fred for triage
@ericstj is this something that you still want since the namespace idea?
I think this request still has merit regardless but its less important if we have a heuristic that works well. Let's wait and see how the namespace suggestion works in practice.