• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Recommendations for deep copying C# object

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Recommendations for deep copying C# object

    Tried a few things but they all fall foul.

    I am reading this article

    Deep Copy of Object in C#

    I tried the reflection method, but if throws an exception about an object not having an empty constructor, Forms.Cursor is the type.

    The serialisation method just seems heavy to me, and I need performance. Perhaps I am wrong.

    Anyone from the congregation done this? If so, best practices and some pointers would be gratefully received.

    I know it's late, and this is only for plan B so take your time.
    Knock first as I might be balancing my chakras.

    #2
    OK you can get a move on now.
    Knock first as I might be balancing my chakras.

    Comment


      #3
      If performance might be an issue, I think you need to provide more details (deja vu) what the object looks like. Is it fundamentally a POD, albeit with sub-objects which are also POD, or does it contain elements which don't conceptually support copying in a neat fashion (like, I dunno, a Thread or something)?
      Originally posted by MaryPoppins
      I'd still not breastfeed a nazi
      Originally posted by vetran
      Urine is quite nourishing

      Comment


        #4
        Originally posted by d000hg View Post
        If performance might be an issue, I think you need to provide more details (deja vu) what the object looks like. Is it fundamentally a POD, albeit with sub-objects which are also POD, or does it contain elements which don't conceptually support copying in a neat fashion (like, I dunno, a Thread or something)?
        If there was any funny business I would have said Doogie.

        It's just a POD, with some PODs.

        What's a POD btw? Is this the C hash equivalent of Pojo?
        Knock first as I might be balancing my chakras.

        Comment


          #5
          Originally posted by suityou01 View Post
          If there was any funny business I would have said Doogie.
          Hmm

          It's just a POD, with some PODs.

          What's a POD btw? Is this the C hash equivalent of Pojo?
          It's a POD but you don't know what a POD is?! Plain Old Data (a C++ term)

          How big is this object, by whatever metric you consider apt?
          Originally posted by MaryPoppins
          I'd still not breastfeed a nazi
          Originally posted by vetran
          Urine is quite nourishing

          Comment


            #6
            Originally posted by d000hg View Post
            Hmm

            It's a POD but you don't know what a POD is?! Plain Old Data (a C++ term)

            How big is this object, by whatever metric you consider apt?
            Well as I said in the OP it is a plan B.

            If I used sheer number of projects, and sheer number of classes and interfaces it's probably the biggest and most complicated thing I have ever ever worked on.

            Why would I use a C++ term for a C hash object? The term here is POCO. Plain Old CLR Object - Wikipedia, the free encyclopedia

            So by the very definition of a POCO, it is not. It wraps a user control that inherits from Forms.Panel. It also inherits from an abstract class I created, which in turn inherits from a few interfaces.

            Basically the object model is a thing of beauty.

            Does any of this help?
            Knock first as I might be balancing my chakras.

            Comment


              #7
              Have you tried serialising the object then restoring it to a different object?
              [Sorry didn't read OP properly]
              I'm not even an atheist so much as I am an antitheist; I not only maintain that all religions are versions of the same untruth, but I hold that the influence of churches, and the effect of religious belief, is positively harmful. [Christopher Hitchens]

              Comment


                #8
                Originally posted by GlenW View Post
                Have you tried serialising the object then restoring it to a different object?
                [Sorry didn't read OP properly]
                That is where I'm thinking of going. It seemed crude when reflection is available, but I wanted a read on what the panel consider best practice for performance.

                It probably took longer to type the explanation of having not read the OP properly than to read the OP properly
                Knock first as I might be balancing my chakras.

                Comment


                  #9
                  Originally posted by suityou01 View Post
                  That is where I'm thinking of going. It seemed crude when reflection is available, but I wanted a read on what the panel consider best practice for performance.

                  It probably took longer to type the explanation of having not read the OP properly than to read the OP properly
                  I'd give it a try, binary serialise to a byte[] then deserialise back to a different object, it may be more efficient than you would expect.
                  I'm not even an atheist so much as I am an antitheist; I not only maintain that all religions are versions of the same untruth, but I hold that the influence of churches, and the effect of religious belief, is positively harmful. [Christopher Hitchens]

                  Comment


                    #10
                    Any use?

                    var serialized = JsonConvert.SerializeObject(source);
                    return JsonConvert.DeserializeObject<T>(serialized);

                    Comment

                    Working...
                    X