提交 295cc813 编写于 作者: S Sam Harwell

Annotate symbol interfaces

上级 dddac7b7
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Emit;
namespace Microsoft.CodeAnalysis.Symbols
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......@@ -57,6 +59,6 @@ public interface IArrayTypeSymbol : ITypeSymbol
/// </summary>
ImmutableArray<CustomModifier> CustomModifiers { get; }
bool Equals(IArrayTypeSymbol other);
bool Equals(IArrayTypeSymbol? other);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Text;
......@@ -57,7 +59,7 @@ public interface IAssemblySymbol : ISymbol
/// </summary>
/// <param name="fullyQualifiedMetadataName">Type name.</param>
/// <returns>Symbol for the type or null if type cannot be found or is ambiguous. </returns>
INamedTypeSymbol GetTypeByMetadataName(string fullyQualifiedMetadataName);
INamedTypeSymbol? GetTypeByMetadataName(string fullyQualifiedMetadataName);
/// <summary>
/// Determines if the assembly might contain extension methods.
......@@ -70,13 +72,13 @@ public interface IAssemblySymbol : ISymbol
/// The name should refer to a non-nested type. If type with this name is not forwarded,
/// null is returned.
/// </summary>
INamedTypeSymbol ResolveForwardedType(string fullyQualifiedMetadataName);
INamedTypeSymbol? ResolveForwardedType(string fullyQualifiedMetadataName);
/// <summary>
/// If this symbol represents a metadata assembly returns the underlying <see cref="AssemblyMetadata"/>.
///
/// Otherwise, this returns <see langword="null"/>.
/// </summary>
AssemblyMetadata GetMetadata();
AssemblyMetadata? GetMetadata();
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
{
internal interface IAssemblySymbolInternal : IAssemblySymbol
{
Version AssemblyVersionPattern { get; }
Version? AssemblyVersionPattern { get; }
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......@@ -32,17 +34,17 @@ public interface IEventSymbol : ISymbol
/// <summary>
/// The 'add' accessor of the event. Null only in error scenarios.
/// </summary>
IMethodSymbol AddMethod { get; }
IMethodSymbol? AddMethod { get; }
/// <summary>
/// The 'remove' accessor of the event. Null only in error scenarios.
/// </summary>
IMethodSymbol RemoveMethod { get; }
IMethodSymbol? RemoveMethod { get; }
/// <summary>
/// The 'raise' accessor of the event. Null if there is no raise method.
/// </summary>
IMethodSymbol RaiseMethod { get; }
IMethodSymbol? RaiseMethod { get; }
/// <summary>
/// The original definition of the event. If the event is constructed from another
......@@ -54,7 +56,7 @@ public interface IEventSymbol : ISymbol
/// <summary>
/// Returns the overridden event, or null.
/// </summary>
IEventSymbol OverriddenEvent { get; }
IEventSymbol? OverriddenEvent { get; }
/// <summary>
/// Returns interface properties explicitly implemented by this event.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......@@ -21,7 +23,7 @@ public interface IFieldSymbol : ISymbol
/// Note, the set of possible associated symbols might be expanded in the future to
/// reflect changes in the languages.
/// </summary>
ISymbol AssociatedSymbol { get; }
ISymbol? AssociatedSymbol { get; }
/// <summary>
/// Returns true if this field was declared as "const" (i.e. is a constant declaration).
......@@ -65,7 +67,7 @@ public interface IFieldSymbol : ISymbol
/// <summary>
/// Gets the constant value of this field
/// </summary>
object ConstantValue { get; }
object? ConstantValue { get; }
/// <summary>
/// Returns custom modifiers associated with the field, or an empty array if there are none.
......@@ -88,6 +90,6 @@ public interface IFieldSymbol : ISymbol
/// This API allows matching a field that represents a named element, such as "Alice"
/// to the corresponding default element field such as "Item1"
/// </remarks>
IFieldSymbol CorrespondingTupleField { get; }
IFieldSymbol? CorrespondingTupleField { get; }
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......@@ -47,7 +49,7 @@ public interface ILocalSymbol : ISymbol
/// <summary>
/// Gets the constant value of this local variable.
/// </summary>
object ConstantValue { get; }
object? ConstantValue { get; }
/// <summary>
/// Returns true if this local variable is function return variable whose name is the function's name,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
internal interface ILocalSymbolInternal : ILocalSymbol
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis
......@@ -147,12 +149,12 @@ public interface IMethodSymbol : ISymbol
/// If this method overrides another method (because it both had the override modifier
/// and there correctly was a method to override), returns the overridden method.
/// </summary>
IMethodSymbol OverriddenMethod { get; }
IMethodSymbol? OverriddenMethod { get; }
/// <summary>
/// If this method can be applied to an object, returns the type of object it is applied to.
/// </summary>
ITypeSymbol ReceiverType { get; }
ITypeSymbol? ReceiverType { get; }
/// <summary>
/// If this method can be applied to an object, returns the top-level nullability of the object it is applied to.
......@@ -163,7 +165,7 @@ public interface IMethodSymbol : ISymbol
/// If this method is a reduced extension method, returns the definition of extension
/// method from which this was reduced. Otherwise, returns null.
/// </summary>
IMethodSymbol ReducedFrom { get; }
IMethodSymbol? ReducedFrom { get; }
/// <summary>
/// If this method is a reduced extension method, returns a type inferred during reduction process for the type parameter.
......@@ -173,13 +175,13 @@ public interface IMethodSymbol : ISymbol
/// <exception cref="System.InvalidOperationException">If this is not a reduced extension method.</exception>
/// <exception cref="System.ArgumentNullException">If <paramref name="reducedFromTypeParameter"/> is null.</exception>
/// <exception cref="System.ArgumentException">If <paramref name="reducedFromTypeParameter"/> doesn't belong to the corresponding <see cref="ReducedFrom"/> method.</exception>
ITypeSymbol GetTypeInferredDuringReduction(ITypeParameterSymbol reducedFromTypeParameter);
ITypeSymbol? GetTypeInferredDuringReduction(ITypeParameterSymbol reducedFromTypeParameter);
/// <summary>
/// If this is an extension method that can be applied to a receiver of the given type,
/// returns a reduced extension method symbol thus formed. Otherwise, returns null.
/// </summary>
IMethodSymbol ReduceExtensionMethod(ITypeSymbol receiverType);
IMethodSymbol? ReduceExtensionMethod(ITypeSymbol receiverType);
/// <summary>
/// Returns interface methods explicitly implemented by this method.
......@@ -216,7 +218,7 @@ public interface IMethodSymbol : ISymbol
/// Note, the set of possible associated symbols might be expanded in the future to
/// reflect changes in the languages.
/// </remarks>
ISymbol AssociatedSymbol { get; }
ISymbol? AssociatedSymbol { get; }
/// <summary>
/// Returns a constructed method given its type arguments.
......@@ -234,19 +236,19 @@ public interface IMethodSymbol : ISymbol
/// If this is a partial method implementation part, returns the corresponding
/// definition part. Otherwise null.
/// </summary>
IMethodSymbol PartialDefinitionPart { get; }
IMethodSymbol? PartialDefinitionPart { get; }
/// <summary>
/// If this is a partial method declaration without a body, and the method is
/// implemented with a body, returns that implementing definition. Otherwise
/// null.
/// </summary>
IMethodSymbol PartialImplementationPart { get; }
IMethodSymbol? PartialImplementationPart { get; }
/// <summary>
/// Platform invoke information, or null if the method isn't a P/Invoke.
/// </summary>
DllImportData GetDllImportData();
DllImportData? GetDllImportData();
/// <summary>
/// If this method is a Lambda method (MethodKind = MethodKind.LambdaMethod) and
......@@ -255,7 +257,7 @@ public interface IMethodSymbol : ISymbol
/// Returns null if the symbol is not a lambda or if it does not have an
/// anonymous delegate associated with it.
/// </summary>
INamedTypeSymbol AssociatedAnonymousDelegate { get; }
INamedTypeSymbol? AssociatedAnonymousDelegate { get; }
/// <summary>
/// Returns a flag indicating whether this symbol has at least one applied/inherited conditional attribute.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis.Symbols
{
internal interface IMethodSymbolInternal : IMethodSymbol
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
using System.Collections.Immutable;
......@@ -23,7 +25,7 @@ public interface IModuleSymbol : ISymbol
/// <summary>
/// Given a namespace symbol, returns the corresponding module specific namespace symbol
/// </summary>
INamespaceSymbol GetModuleNamespace(INamespaceSymbol namespaceSymbol);
INamespaceSymbol? GetModuleNamespace(INamespaceSymbol namespaceSymbol);
/// <summary>
/// Returns an array of assembly identities for assemblies referenced by this module.
......@@ -44,6 +46,6 @@ public interface IModuleSymbol : ISymbol
///
/// Otherwise, this returns <see langword="null"/>.
/// </summary>
ModuleMetadata GetMetadata();
ModuleMetadata? GetMetadata();
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Reflection;
......@@ -100,13 +102,13 @@ public interface INamedTypeSymbol : ITypeSymbol
/// Such a type will be classified as a delegate but its DelegateInvokeMethod
/// would be null.
/// </summary>
IMethodSymbol DelegateInvokeMethod { get; }
IMethodSymbol? DelegateInvokeMethod { get; }
/// <summary>
/// For enum types, gets the underlying type. Returns null on all other
/// kinds of types.
/// </summary>
INamedTypeSymbol EnumUnderlyingType { get; }
INamedTypeSymbol? EnumUnderlyingType { get; }
/// <summary>
/// Returns the type symbol that this type was constructed from. This type symbol
......@@ -154,7 +156,7 @@ public interface INamedTypeSymbol : ITypeSymbol
/// Note, the set of possible associated symbols might be expanded in the future to
/// reflect changes in the languages.
/// </summary>
ISymbol AssociatedSymbol { get; }
ISymbol? AssociatedSymbol { get; }
/// <summary>
/// Determines if the symbol might contain extension methods.
......@@ -169,7 +171,7 @@ public interface INamedTypeSymbol : ITypeSymbol
/// which is at the 8th (one based) position is always a symbol for another tuple,
/// rather than its underlying type.
/// </summary>
INamedTypeSymbol TupleUnderlyingType { get; }
INamedTypeSymbol? TupleUnderlyingType { get; }
/// <summary>
/// Returns fields that represent tuple elements for types that are tuples.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......@@ -47,7 +49,7 @@ public interface INamespaceSymbol : INamespaceOrTypeSymbol
/// <summary>
/// The containing compilation for compilation namespaces.
/// </summary>
Compilation ContainingCompilation { get; }
Compilation? ContainingCompilation { get; }
/// <summary>
/// If a namespace is an assembly or compilation namespace, it may be composed of multiple
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Text;
......@@ -76,7 +78,7 @@ public interface IParameterSymbol : ISymbol
/// is the default value of the struct type.
/// </remarks>
/// <exception cref="System.InvalidOperationException">The parameter has no default value.</exception>
object ExplicitDefaultValue { get; }
object? ExplicitDefaultValue { get; }
/// <summary>
/// Get the original definition of this symbol. If this symbol is derived from another
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
......@@ -67,12 +69,12 @@ public interface IPropertySymbol : ISymbol
/// <summary>
/// The 'get' accessor of the property, or null if the property is write-only.
/// </summary>
IMethodSymbol GetMethod { get; }
IMethodSymbol? GetMethod { get; }
/// <summary>
/// The 'set' accessor of the property, or null if the property is read-only.
/// </summary>
IMethodSymbol SetMethod { get; }
IMethodSymbol? SetMethod { get; }
/// <summary>
/// The original definition of the property. If the property is constructed from another
......@@ -84,7 +86,7 @@ public interface IPropertySymbol : ISymbol
/// <summary>
/// Returns the overridden property, or null.
/// </summary>
IPropertySymbol OverriddenProperty { get; }
IPropertySymbol? OverriddenProperty { get; }
/// <summary>
/// Returns interface properties explicitly implemented by this property.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Reflection;
......@@ -12,11 +14,11 @@ internal interface ISourceAssemblySymbolInternal : ISourceAssemblySymbol
/// <summary>
/// The contents of the AssemblySignatureKeyAttribute
/// </summary>
string SignatureKey { get; }
string? SignatureKey { get; }
AssemblyHashAlgorithm HashAlgorithm { get; }
Version AssemblyVersionPattern { get; }
Version? AssemblyVersionPattern { get; }
bool InternalsAreVisible { get; }
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis.Symbols
{
internal interface ISymbolInternal : ISymbol
{
#nullable disable // Skipped for now https://github.com/dotnet/roslyn/issues/39166
Compilation DeclaringCompilation { get; }
#nullable enable
/// <summary>
/// Allows a symbol to support comparisons that involve child type symbols
......@@ -13,6 +17,6 @@ internal interface ISymbolInternal : ISymbol
/// Because TypeSymbol equality can differ based on e.g. nullability, any symbols that contain TypeSymbols can also differ in the same way
/// This call allows the symbol to accept a comparison kind that should be used when comparing its contained types
/// </remarks>
bool Equals(ISymbol other, TypeCompareKind compareKind);
bool Equals(ISymbol? other, TypeCompareKind compareKind);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......@@ -15,7 +17,7 @@ internal interface ISynthesizedMethodBodyImplementationSymbol
/// The symbol whose body lowering produced this synthesized symbol,
/// or null if the symbol is synthesized based on declaration.
/// </summary>
IMethodSymbol Method { get; }
IMethodSymbol? Method { get; }
/// <summary>
/// True if this symbol body needs to be updated when the <see cref="Method"/> body is updated.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis
......@@ -33,12 +35,12 @@ public interface ITypeParameterSymbol : ITypeSymbol
/// <summary>
/// The method that declares the type parameter, or null.
/// </summary>
IMethodSymbol DeclaringMethod { get; }
IMethodSymbol? DeclaringMethod { get; }
/// <summary>
/// The type that declares the type parameter, or null.
/// </summary>
INamedTypeSymbol DeclaringType { get; }
INamedTypeSymbol? DeclaringType { get; }
/// <summary>
/// True if the reference type constraint (<c>class</c>) was specified for the type parameter.
......@@ -94,6 +96,6 @@ public interface ITypeParameterSymbol : ITypeSymbol
/// If this is a type parameter of a reduced extension method, gets the type parameter definition that
/// this type parameter was reduced from. Otherwise, returns Nothing.
/// </summary>
ITypeParameterSymbol ReducedFrom { get; }
ITypeParameterSymbol? ReducedFrom { get; }
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.CodeAnalysis
{
......@@ -26,7 +29,7 @@ public interface ITypeSymbol : INamespaceOrTypeSymbol
/// and pointer types do not have a base type. The base type of a type parameter
/// is its effective base class.
/// </summary>
INamedTypeSymbol BaseType { get; }
INamedTypeSymbol? BaseType { get; }
/// <summary>
/// Gets the set of interfaces that this type directly implements. This set does not include
......@@ -95,7 +98,7 @@ public interface ITypeSymbol : INamespaceOrTypeSymbol
/// <param name="interfaceMember">
/// Must be a non-null interface property, method, or event.
/// </param>
ISymbol FindImplementationForInterfaceMember(ISymbol interfaceMember);
ISymbol? FindImplementationForInterfaceMember(ISymbol interfaceMember);
/// <summary>
/// True if the type is ref-like, meaning it follows rules similar to CLR by-ref variables. False if the type
......@@ -123,7 +126,7 @@ public interface ITypeSymbol : INamespaceOrTypeSymbol
/// <param name="topLevelNullability">The top-level nullability to use for formatting.</param>
/// <param name="format">Format or null for the default.</param>
/// <returns>A formatted string representation of the symbol with the given nullability.</returns>
string ToDisplayString(NullableFlowState topLevelNullability, SymbolDisplayFormat format = null);
string ToDisplayString(NullableFlowState topLevelNullability, SymbolDisplayFormat? format = null);
/// <summary>
/// Converts a symbol to an array of string parts, each of which has a kind. Useful
......@@ -132,7 +135,7 @@ public interface ITypeSymbol : INamespaceOrTypeSymbol
/// <param name="topLevelNullability">The top-level nullability to use for formatting.</param>
/// <param name="format">Format or null for the default.</param>
/// <returns>A read-only array of string parts.</returns>
ImmutableArray<SymbolDisplayPart> ToDisplayParts(NullableFlowState topLevelNullability, SymbolDisplayFormat format = null);
ImmutableArray<SymbolDisplayPart> ToDisplayParts(NullableFlowState topLevelNullability, SymbolDisplayFormat? format = null);
/// <summary>
/// Converts a symbol to a string that can be displayed to the user. May be tailored to a
......@@ -148,7 +151,7 @@ public interface ITypeSymbol : INamespaceOrTypeSymbol
SemanticModel semanticModel,
NullableFlowState topLevelNullability,
int position,
SymbolDisplayFormat format = null);
SymbolDisplayFormat? format = null);
/// <summary>
/// Convert a symbol to an array of string parts, each of which has a kind. May be tailored
......@@ -164,19 +167,19 @@ public interface ITypeSymbol : INamespaceOrTypeSymbol
SemanticModel semanticModel,
NullableFlowState topLevelNullability,
int position,
SymbolDisplayFormat format = null);
SymbolDisplayFormat? format = null);
}
// Intentionally not extension methods. We don't want them ever be called for symbol classes
// Once Default Interface Implementations are supported, we can move these methods into the interface.
static internal class ITypeSymbolHelpers
{
internal static bool IsNullableType(ITypeSymbol typeOpt)
internal static bool IsNullableType([NotNullWhen(returnValue: true)] ITypeSymbol? typeOpt)
{
return typeOpt?.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T;
}
internal static bool IsNullableOfBoolean(ITypeSymbol type)
internal static bool IsNullableOfBoolean([NotNullWhen(returnValue: true)] ITypeSymbol? type)
{
return IsNullableType(type) && IsBooleanType(GetNullableUnderlyingType(type));
}
......@@ -187,42 +190,43 @@ internal static ITypeSymbol GetNullableUnderlyingType(ITypeSymbol type)
return ((INamedTypeSymbol)type).TypeArguments[0];
}
internal static bool IsBooleanType(ITypeSymbol type)
internal static bool IsBooleanType([NotNullWhen(returnValue: true)] ITypeSymbol? type)
{
return type?.SpecialType == SpecialType.System_Boolean;
}
internal static bool IsObjectType(ITypeSymbol type)
internal static bool IsObjectType([NotNullWhen(returnValue: true)] ITypeSymbol? type)
{
return type?.SpecialType == SpecialType.System_Object;
}
internal static bool IsSignedIntegralType(ITypeSymbol type)
internal static bool IsSignedIntegralType([NotNullWhen(returnValue: true)] ITypeSymbol? type)
{
return type?.SpecialType.IsSignedIntegralType() == true;
}
internal static bool IsUnsignedIntegralType(ITypeSymbol type)
internal static bool IsUnsignedIntegralType([NotNullWhen(returnValue: true)] ITypeSymbol? type)
{
return type?.SpecialType.IsUnsignedIntegralType() == true;
}
internal static bool IsNumericType(ITypeSymbol type)
internal static bool IsNumericType([NotNullWhen(returnValue: true)] ITypeSymbol? type)
{
return type?.SpecialType.IsNumericType() == true;
}
internal static ITypeSymbol GetEnumUnderlyingType(ITypeSymbol type)
internal static ITypeSymbol? GetEnumUnderlyingType(ITypeSymbol? type)
{
return (type as INamedTypeSymbol)?.EnumUnderlyingType;
}
internal static ITypeSymbol GetEnumUnderlyingTypeOrSelf(ITypeSymbol type)
[return: NotNullIfNotNull(parameterName: "type")]
internal static ITypeSymbol? GetEnumUnderlyingTypeOrSelf(ITypeSymbol? type)
{
return GetEnumUnderlyingType(type) ?? type;
}
internal static bool IsDynamicType(ITypeSymbol type)
internal static bool IsDynamicType([NotNullWhen(returnValue: true)] ITypeSymbol? type)
{
return type?.Kind == SymbolKind.DynamicType;
}
......
......@@ -223,7 +223,7 @@ static bool IsPropertyWithNonPublicImplementableAccessor(ISymbol member)
return IsNonPublicImplementableAccessor(property.GetMethod) || IsNonPublicImplementableAccessor(property.SetMethod);
}
static bool IsNonPublicImplementableAccessor(IMethodSymbol accessor)
static bool IsNonPublicImplementableAccessor(IMethodSymbol? accessor)
{
return accessor != null && IsImplementable(accessor) && accessor.DeclaredAccessibility != Accessibility.Public;
}
......
......@@ -1100,7 +1100,9 @@ private static XNode[] RewriteMany(ISymbol symbol, Compilation compilation, XNod
if (methodSymbol.MethodKind == MethodKind.Constructor || methodSymbol.MethodKind == MethodKind.StaticConstructor)
{
var baseType = memberSymbol.ContainingType.BaseType;
#nullable disable // Can 'baseType' be null here? https://github.com/dotnet/roslyn/issues/39166
return baseType.Constructors.Where(c => IsSameSignature(methodSymbol, c)).FirstOrDefault();
#nullable enable
}
else
{
......
......@@ -198,7 +198,7 @@ public static bool IsAnonymousType([NotNullWhen(returnValue: true)] this INamedT
// Now we need to walk the base type chain, but we start at the first type that actually
// has the interface directly in its interface hierarchy.
var seenTypeDeclaringInterface = false;
for (var currentType = typeSymbol; currentType != null; currentType = currentType.BaseType)
for (ITypeSymbol? currentType = typeSymbol; currentType != null; currentType = currentType.BaseType)
{
seenTypeDeclaringInterface = seenTypeDeclaringInterface ||
currentType.GetOriginalInterfacesAndTheirBaseInterfaces().Contains(interfaceType.OriginalDefinition);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册