Created
February 12, 2026 11:12
-
-
Save ufcpp/c27dcb71b277179a3b7e607bf9cb5af9 to your computer and use it in GitHub Desktop.
拡張プロパティでフィールドへの UnsafeAccessor 書けそう。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Runtime.CompilerServices; | |
| var a = new A(); | |
| // a.Value() = 1; ではなく、() なしでフィールド参照。 | |
| a.Value = 1; | |
| Console.WriteLine(a); | |
| static class X | |
| { | |
| extension([UnsafeAccessorType("A")] object @this) | |
| { | |
| // 拡張プロパティでフィールドへの UnsafeAccessor 書けそう。 | |
| public extern ref int Value | |
| { | |
| [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_value")] | |
| get; | |
| } | |
| } | |
| } | |
| internal class A | |
| { | |
| private int _value; | |
| public override string ToString() => $"A({_value})"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment