Skip to content

Commit

Permalink
Expose nullability info (#54985)
Browse files Browse the repository at this point in the history
* Expose nullability info from Reflection
  • Loading branch information
buyaa-n committed Jul 13, 2021
1 parent d2e9f42 commit 62966bc
Show file tree
Hide file tree
Showing 6 changed files with 1,602 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Missing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Module.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ModuleResolveEventHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\NullabilityInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\NullabilityInfoContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscateAssemblyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscationAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ParameterAttributes.cs" />
Expand Down Expand Up @@ -2319,4 +2321,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryNegationOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryPlusOperators.cs" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.ObjectModel;

namespace System.Reflection
{
/// <summary>
/// A class that represents nullability info
/// </summary>
public sealed class NullabilityInfo
{
internal NullabilityInfo(Type type, NullabilityState readState, NullabilityState writeState,
NullabilityInfo? elementType, NullabilityInfo[] typeArguments)
{
Type = type;
ReadState = readState;
WriteState = writeState;
ElementType = elementType;
GenericTypeArguments = typeArguments;
}

/// <summary>
/// The <see cref="System.Type" /> of the member or generic parameter
/// to which this NullabilityInfo belongs
/// </summary>
public Type Type { get; }
/// <summary>
/// The nullability read state of the member
/// </summary>
public NullabilityState ReadState { get; internal set; }
/// <summary>
/// The nullability write state of the member
/// </summary>
public NullabilityState WriteState { get; internal set; }
/// <summary>
/// If the member type is an array, gives the <see cref="NullabilityInfo" /> of the elements of the array, null otherwise
/// </summary>
public NullabilityInfo? ElementType { get; }
/// <summary>
/// If the member type is a generic type, gives the array of <see cref="NullabilityInfo" /> for each type parameter
/// </summary>
public NullabilityInfo[] GenericTypeArguments { get; }
}

/// <summary>
/// An enum that represents nullability state
/// </summary>
public enum NullabilityState
{
/// <summary>
/// Nullability context not enabled (oblivious)
/// </summary>
Unknown,
/// <summary>
/// Non nullable value or reference type
/// </summary>
NotNull,
/// <summary>
/// Nullable value or reference type
/// </summary>
Nullable
}
}
Loading

0 comments on commit 62966bc

Please sign in to comment.