potisanのプログラミングメモ

趣味のプログラマーがプログラミング関係で気になったことや調べたことをいつでも忘れられるようにメモするブログです。はてなブログ無料版なので記事の上の方はたぶん広告です。記事中にも広告挿入されるみたいです。

C#&MSVS 17.5.0 Preview 3.0 ユーザーコントロールのobject、nint、nuint型プロパティはプロパティウィンドウで読み取り専用

ユーザーコントロールのobject、nint、nuint型プロパティはプロパティウィンドウで読み取り専用になります。

// UserControl1.Designer.csとUserControl1.resxは既定値なので省略します。
namespace UserControlTest1;

public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
    }

    public object? ObjectProp { get; set; } = null;
    public sbyte Int8Prop { get; set; }
    public byte UInt8Prop { get; set; }
    public short Int16Prop { get; set; }
    public ushort UInt16Prop { get; set; }
    public int Int32Prop { get; set; }
    public uint UInt32Prop { get; set; }
    public long Int64Prop { get; set; }
    public ulong UInt64Prop { get; set; }
    public nint NIntProp { get; set; }
    public nuint NUIntProp { get; set; }
    public char CharProp { get; set; }
    public string StringProp { get; set; } = "123";
    public float FloatProp { get; set; }
    public double DoubleProp { get; set; }
    public bool BoolProp { get; set; }
    public int[] IntArrayProp { get; set; } = new[] { 1, 2, 3 };
    public char[] CharArrayProp { get; set; } = new[] { 'A', 'B', 'C' };
    public byte[] ByteArrayProp { get; set; } = new byte[] { 1, 2, 3 };
    public string[] StringArrayProp { get; set; } = new[] { "A", "B", "C" };
    public bool[] BoolArrayProp { get; set; } = new[] { false, true };
}

nint、nuint型プロパティはTypeConverterを適用すると別の型として編集できます。

    [TypeConverter(typeof(Int32Converter))]
    public nint NIntProp { get; set; }
    [TypeConverter(typeof(UInt32Converter))]
    public nuint NUIntProp { get; set; }