Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
bilalkhan #1
Member since Oct 2016 · 81 posts · Location: Pakistan
Group memberships: Members
Show profile · Link to this post
Subject: Create A Copy Of Message
How to create a copy of message, instead of copy every property from orignal Message.


Message copyMessage=orignalMessage; //this will create by refrence changes in any object will reflect in another


this is a hard one to create


  1. Message message = new Message();
  2. message.id= orignalMessage.id; //i am creating the copy of the object here


agsxmpp providing any flexibility to create the copy of object ?
This post was edited on 2017-07-13, 16:30 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You can easily create an extension for clone by either:

  • Recursive traverse the Xml tree and copy all nodes with attributes.

or

  • just serialize the object with ToString(), and then deserialize with the Document.LoadXml method.

Alex
This post was edited on 2017-07-13, 16:59 by Alex.
Avatar
bilalkhan #3
Member since Oct 2016 · 81 posts · Location: Pakistan
Group memberships: Members
Show profile · Link to this post
thanks

  1. var doc = new ChatLibrary.Xml.Dom.Document();
  2. doc.LoadXml(message.ToString());
  3. Message messages = new Message();
  4. message = doc.RootElement as Message;
This post was edited on 2017-07-13, 16:59 by Alex.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS