Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eng/MSBuild/LegacySupport.props
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@
<ItemGroup Condition="'$(InjectCollectionBuilderAttributesOnLegacy)' == 'true' AND ('$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netcoreapp3.1')">
<Compile Include="$(MSBuildThisFileDirectory)\..\..\src\LegacySupport\CollectionBuilder\*.cs" LinkBase="LegacySupport\CollectionBuilder" />
</ItemGroup>

<ItemGroup Condition="'$(InjectNullabilityInfoContextOnLegacy)' == 'true' AND ('$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netcoreapp3.1')">
<Compile Include="$(MSBuildThisFileDirectory)\..\..\src\LegacySupport\NullabilityInfoContext\*.cs" LinkBase="LegacySupport\NullabilityInfoContext" />
</ItemGroup>
</Project>
75 changes: 75 additions & 0 deletions src/LegacySupport/NullabilityInfoContext/NullabilityInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if !NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;

#pragma warning disable SA1623 // Property summary documentation should match accessors

namespace System.Reflection
{
/// <summary>
/// A class that represents nullability info.
/// </summary>
[ExcludeFromCodeCoverage]
internal 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>
internal 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,
}
}
#endif
Loading
Loading