I'm writing a Roslyn diagnostic analyzer. I want to tell if System.Collections.Immutable is referenced in RegisterCompilationStartAction before I register any other actions. This is the way I'm going about it so far:
context.RegisterCompilationStartAction(compilationStartContext =>
{
var compilation = compilationStartContext.Compilation;
if (compilation.GetTypeByMetadataName("System.Collections.Immutable.ImmutableArray`1") == null)
{
return;
}
...
});
This works, but I don't feel it's the cleanest way to do this. Can I somehow get a MetadataReference corresponding to the assembly name instead and check if it's null, like GetMetadataReference("System.Collections.Immutable") == null? (GetMetadataReference doesn't accept a string, so that doesn't actually work.) If not, any other cleaner way to do this that doesn't involve picking out a particular type? Thanks.