Dear friends,
When an object is cloned through serialization in memory, to make a
copy. clearly the <NonSerialize d> fields are not copied.
To copy them I usually use (this is a very useful simple Sub):
'------------------ copying non serialized ---------
Public Sub CopiaFieldsNotS erialized(ByVal Destinazione As Object,
ByVal Origine As Object)
Dim FieldInfos As FieldInfo() =
Origine.GetType .GetFields((Bin dingFlags.Stati c Or BindingFlags.In stance
Or BindingFlags.No nPublic Or BindingFlags.Pu blic))
For Each FieldInfo As FieldInfo In FieldInfos
With FieldInfo
If .IsNotSerialize d Then
.SetValue(Desti nazione, .GetValue(Origi ne))
End If
End With
Next FieldInfo
End Sub
'------------------------------------------
while the above works for all most common cases, it does not work in
general. Two are the problems:
- It must be generalized by introducing recursion. In fact
if a NonSerialized member class has other NonSerialed fields
these will not be relinked by the above Sub.
- Another problem is breaking circular reference. In fact
it is common that there is a nonserialized reference to a parental
class.
I would like to have assistance and collaboration to refine this sub so
that all the nonserialized references can be successfully restore, as
they are in the object being cloned.
Thank you very much.
-Pamela
..NET developer
Datatime Time
http://151.100.3.84/technicalpreview/