Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4031196
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:34:02+00:00 2026-05-20T11:34:02+00:00

I have a class with childrens. All childs must have a reference to my

  • 0

I have a class with childrens. All childs must have a reference to my root object. Everything is going fine until I deserialize my object. When deserialization occurs, Deserialization do a New() on my child objects so even if before a SetParent has been called, that child object has been replace by a new one and no SetParent has been called. So after Deserialization, none of my child objects know his parent. The object Root is use by a lot of applications and i don’t want all those applications to call the SetParent.

I’ve look for a event AfterDeserialization but haven’t found any. I’ve look through reflection and haven’t found a way to find the parent object. I’ve seen I could Implements ISerializable but find it a bit heavy to manage all the deserialization process (I have about 170 properties in this object).

Can I Implements ISerializable and call a base method that do all the things and after, just call my SetParent function? Or is there a way with reflection to find the parent of an instance of an object that I haven’t found in my research? Or anyone would have any other suggestions?

Public Class Root
    Private _a As Child1
    Private _b As Child2

    Public Property a() As Child1
        Get
            Return _a
        End Get
        Set(ByVal value As Child1)
            _a = value
        End Set
    End Property
    Public Property b() As Child2
        Get
            Return _b
        End Get
        Set(ByVal value As Child2)
            _b = value
        End Set
    End Property

    Public Sub New()
        a = New Child1
        b = New Child2
        SetParent()
    End Sub

    Friend Sub SetParent()
        a.SetParent(Me)
        b.SetParent(Me)
    End Sub
End Class

Public Class Child1
    Private _parent As Root

    Friend Sub SetParent(ByRef parent As Root)
        _parent = parent
    End Sub
End Class

Public Class Child2
    Private _parent As Root
    Private _a As New Child3

    Public Property a() As Child3
        Get
            Return _a
        End Get
        Set(ByVal value As Child3)
            _a = value
        End Set
    End Property

    Friend Sub SetParent(ByRef parent As Root)
        a = New Child3
        _parent = parent
        a.SetParent(parent)
    End Sub
End Class

Public Class Child3
    Private _parent As Root

    Friend Sub SetParent(ByRef parent As Root)
        _parent = parent
    End Sub
End Class

Thanks for your help! :o)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:34:02+00:00Added an answer on May 20, 2026 at 11:34 am

    Is it possible to set the parent in the parent property setter?

    If you parent is serialize too, the deserialization will call the setter.

    ex:

       Public Class Root
           ...
           Public Property a() As Child1  
            Get       
                Return _a     
            End Get
            Set(ByVal value As Child1)      
               _a = value    
               _a.SetParent(Me)
            End Set   
          End Property 
          ...
       End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class A, which exposes an event. an object of class B subscribed
I have a class called Parent , and I'm storing these object's in the
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
I have a class object that stores some properties that are lists of other
How do I check if all children, or all selectors, have same class? The
I have been struggling with this all day and have tried going through the
I have a class which has a function to retrieve children elements from a
Should a Singleton class be allowed to have children? Should we seal it? What
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.