Skip to content

Containing{Type/Assembly/Symbol/etc} are marked nullable oblivious #58107

Open
@agocke

Description

@agocke

These are some of the most common places to receive null from the Roslyn type system, but they're annotated as non-nullable, so it's easy to forget to check for null. See

#nullable disable // Skipped for now https://github.com/dotnet/roslyn/issues/39166
#pragma warning disable RS0041 // uses oblivious reference types
/// <summary>
/// Gets the <see cref="ISymbol"/> for the immediately containing symbol.
/// </summary>
ISymbol ContainingSymbol { get; }
/// <summary>
/// Gets the <see cref="IAssemblySymbol"/> for the containing assembly. Returns null if the
/// symbol is shared across multiple assemblies.
/// </summary>
IAssemblySymbol ContainingAssembly { get; }
/// <summary>
/// Gets the <see cref="IModuleSymbol"/> for the containing module. Returns null if the
/// symbol is shared across multiple modules.
/// </summary>
IModuleSymbol ContainingModule { get; }
/// <summary>
/// Gets the <see cref="INamedTypeSymbol"/> for the containing type. Returns null if the
/// symbol is not contained within a type.
/// </summary>
INamedTypeSymbol ContainingType { get; }
/// <summary>
/// Gets the <see cref="INamespaceSymbol"/> for the nearest enclosing namespace. Returns null if the
/// symbol isn't contained in a namespace.
/// </summary>
INamespaceSymbol ContainingNamespace { get; }
#nullable enable
#pragma warning restore RS0041 // uses oblivious reference types

  • ContainingSymbol
  • ContainingAssembly
  • ContainingModule
  • ContainingType
  • ContainingNamespace

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions