.NET I want to clone a value type's fields. How can i set a field value on a value type using reflection (or something else dynamically)?
This works for reference types but not for value types. I understand why but I don't know an alternative.
shared function clone(of t)(original as t) as t
dim cloned as t
'if class then execute parameterless constructor
if getType(t).isClass then cloned = reflector.construct(of t)()
dim public_fields = original.getType.getFields()
for each field in public_fields
dim original_value = field.getValue(original)
'this won't work for value type, but it does work for reference type ???
field.setValue(cloned, original_value)
next
return cloned
end function