private void LookForInstantiationsThatReferToTypesNotAvailableAtRuntime(SyntaxNodeAnalysisContext context)
{
var objectCreation = context.Node as ObjectCreationExpressionSyntax;
if (objectCreation == null)
return;
foreach (var type in GetAllReferencedTypes(objectCreation.Type, context))
{
var typeInfo = context.SemanticModel.GetTypeInfo(type);
if ((typeInfo.Type == null) || (typeInfo.Type is IErrorTypeSymbol))
{
// The documentation for the "Type" property says that "For expressions that do not have a type, null is returned. If the type
// could not be determined due to an error, than an IErrorTypeSymbol is returned" , so we'll just push on in those cases
continue;
}
// Note: ReactElement is sealed and so we don't have to worry about whether the current type is derived from it - it's either
// simply a ReactElement or it's not
if (typeInfo.Type.IsPartOfBridgeReact() && (typeInfo.Type.Name == "ReactElement"))
{
context.ReportDiagnostic(Diagnostic.Create(
InstantiationsThatReferToTypesNotAvailableAtRuntimeRule,
type.GetLocation()
));
}
}
}