3

次のバイト配列がある場合:

byte[] someArray = new byte { 0, 1, 2 };

リフレクションを介してクラスのインスタンスにコピーしたいのですが、どうすればできますか?

// Inside a class method

PropertyInfo property = this.GetType().GetProperty("propertyName");

if(property.PropertyType == typeof(System.Byte[]))
{
    property.SetValue(this, ???, ???); // How to set an array?
} 
4

1 に答える 1

7

Array.Clone()を使用します。

if(property.PropertyType == typeof(System.Byte[]))
{
    property.SetValue(this, someArray.Clone(), null); 
} 
于 2013-01-05T04:41:12.297 に答える