如果我有以下字节数组:
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?
}
最佳答案
使用Array.Clone() :
if(property.PropertyType == typeof(System.Byte[]))
{
property.SetValue(this, someArray.Clone(), null);
}
关于c# - 如何使用反射复制数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14168525/