consulo / consulo-csharp

Languages: C#
Apache License 2.0
50 stars 6 forks source link

New option for runtime/compiler nullable context check. C# 8.0 #554

Open VISTALL opened 4 years ago

VISTALL commented 4 years ago

Need option for UI too.

Initial from https://github.com/consulo/consulo-csharp/issues/553

CS8632=The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

-nullable[+|-]                Specify nullable context option enable|disable.
-nullable:{enable|disable|warnings|annotations}
                              Specify nullable context option enable|disable|warnings|annotations.

Also need load this option from bytecode

System.Runtime.CompilerServices.NullableContextAttribute

namespace System.Runtime.CompilerServices
{
    [System.AttributeUsage(
        AttributeTargets.Module |
        AttributeTargets.Class |
        AttributeTargets.Delegate |
        AttributeTargets.Interface |
        AttributeTargets.Method |
        AttributeTargets.Struct,
        AllowMultiple = false,
        Inherited = false)]
    public sealed class NullableContextAttribute : Attribute
    {
        public readonly byte Flag;
        public NullableContextAttribute(byte flag)
        {
            Flag = flag;
        }
    }

    public enum NullableMembers
    {
        Public = 0,   // public and protected only
        Internal = 1, // public, protected, internal
        All = 2,
    }

    [System.AttributeUsage(AttributeTargets.Module, AllowMultiple = false)]
    public sealed class NullableMembersAttribute : Attribute
    {
        public readonly NullableMembers Members;
        public NullableMembersAttribute(NullableMembers members)
        {
            Members = members;
        }
    }
}
VISTALL commented 4 years ago

Also new options was added to MSBuild, like NullableContextOptions + Nullable

VISTALL commented 4 years ago

Also new processor directive

#nullable enable

#nullable restore
VISTALL commented 4 years ago

Also

System.Runtime.CompilerServices.NullableAttribute