Dear friends,
When an object is cloned through serialization in memory, to make a
copy. clearly the <NonSerialized> fields are not copied.
To copy them I usually use (this is a very useful simple Sub):
'------------------ copying non serialized ---------
Public Sub CopiaFieldsNotSerialized(ByVal Destinazione As Object,
ByVal Origine As Object)
Dim FieldInfos As FieldInfo() =
Origine.GetType.GetFields((BindingFlags.Static Or BindingFlags.Instance
Or BindingFlags.NonPublic Or BindingFlags.Public))
For Each FieldInfo As FieldInfo In FieldInfos
With FieldInfo
If .IsNotSerialized Then
.SetValue(Destinazione, .GetValue(Origine))
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/