Skip to content

null許容参照型の有効化 #10

Open

Description

@miyaji255

なぜか以下のコードがうまく働かないので放置

#if UNITY_2020_2_OR_NEWER
#nullable enable
#endif

Activity

  1. Gs-itisitcat commented on Apr 13, 2023

    @Gs-itisitcat
    Member

    System.Diagnostics.CodeAnalysis名前空間を使用し、以下のように記述することで、パッケージ側で#nullableを使用せずに、使用側で#nullable enableした際に警告を発することが可能でした。

    #if UNITY_2020_2_OR_NEWER
    using System.Diagnostics.CodeAnalysis;
    #endif
    
    public static class TestExtension
    {
        #if UNITY_2020_2_OR_NEWER
        public static ParticleSystem TestExtensionMethod([DisallowNull]this ParticleSystem particleSystem, int value)
        #else
        public static ParticleSystem TestExtensionMethod(this ParticleSystem particleSystem, int value)
        #endif
        {
            Debug.Log(value);
            return particleSystem;
        }
    }

    image

    このコードはUnity 2019.4.31f1で問題なくコンパイルされました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions