If I have the following byte array:
byte[] someArray = new byte { 0, 1, 2 };
and I want to copy it to an instance of a class through reflection, how can you do that?
// Inside a class method
PropertyInfo property = this.GetType().GetProperty("propertyName");
if(property.PropertyType == typeof(System.Byte[]))
{
property.SetValue(this, ???, ???); // How to set an array?
}
Use Array.Clone():
if(property.PropertyType == typeof(System.Byte[]))
{
property.SetValue(this, someArray.Clone(), null);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With