Open4
C#のNull許容参照型のメタデータ
roslyn/docs/features/nullable-metadata.md
Each type reference in metadata may have an associated NullableAttribute with a byte[] where each byte represents nullability: 0 for oblivious, 1 for not annotated, and 2 for annotated.
using System;
using System.Collections.Generic;
#nullable enable
class Program
{
public string? s;
public Dictionary<string, object?>? d;
public int[] a;
public object[]? b;
public object?[]? c;
public Object?[] e;
public Object? M(String a, String? b, String[]? c){ return default;}
}
#nullable disable
class C
{
string s;
string? s2;
}
[System.Runtime.CompilerServices.NullableContext(2)]
[System.Runtime.CompilerServices.Nullable(0)]
internal class Program
{
public string s;
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1,
2
})]
public Dictionary<string, object> d;
[System.Runtime.CompilerServices.Nullable(1)]
public int[] a;
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
public object[] b;
public object[] c;
[System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
public object[] e;
public object M([System.Runtime.CompilerServices.Nullable(1)] string a, string b, [System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})] string[] c)
{
return null;
}
}
internal class C
{
private string s;
[System.Runtime.CompilerServices.Nullable(2)]
private string s2;
}
NullableAttributeの引数の1
とか2
はNullableFlowState Enum?
それともNullableAnnotation Enum?
-> NullableAnnotationが近い。
Annotated | 2 | The expression is annotated (does have a ?). |
None | 0 | The expression has not been analyzed, or the syntax is not an expression (such as a statement). |
NotAnnotated | 1 | The expression is not annotated (does not have a ?). |
NullableContextAttributeの引数の1とか2はNullableContextOptions Enum?
それともNullableContext Enum