Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
miyaji255 opened this issue Mar 20, 2023 · 1 comment
Open

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

miyaji255 opened this issue Mar 20, 2023 · 1 comment

Comments

@miyaji255
Copy link
Contributor

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

#if UNITY_2020_2_OR_NEWER
#nullable enable
#endif
@Gs-itisitcat
Copy link
Member

Gs-itisitcat commented Apr 13, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants