NullableFlowStateExtensions.cs 1.4 KB
Newer Older
1 2 3
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System.Diagnostics;
F
Fredric Silberberg 已提交
4
using Roslyn.Utilities;
5 6 7 8 9 10 11 12 13 14

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
    internal static class NullableFlowStateExtensions
    {
        internal static CodeAnalysis.NullableFlowState ToPublicFlowState(this NullableFlowState nullableFlowState)
        {
            Debug.Assert((CodeAnalysis.NullableFlowState)(NullableFlowState.NotNull + 1) == CodeAnalysis.NullableFlowState.NotNull);
            return (CodeAnalysis.NullableFlowState)nullableFlowState + 1;
        }
F
Fredric Silberberg 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27

        // PROTOTYPE(nullable-api): remove if possible
        public static NullableFlowState ToInternalFlowState(this CodeAnalysis.NullableFlowState flowState)
        {
            Debug.Assert((CodeAnalysis.NullableFlowState)(NullableFlowState.NotNull + 1) == CodeAnalysis.NullableFlowState.NotNull);
            return flowState switch
            {
                CodeAnalysis.NullableFlowState.NotApplicable => NullableFlowState.NotNull,
                CodeAnalysis.NullableFlowState.NotNull => NullableFlowState.NotNull,
                CodeAnalysis.NullableFlowState.MaybeNull => NullableFlowState.MaybeNull,
                _ => throw ExceptionUtilities.UnexpectedValue(flowState)
            };
        }
28 29
    }
}