Home > DeveloperSection > Forums > How to update Current object instance.
James Smith

Total Post:48

Posted on    April-16-2011 2:19 AM

 C# C# 

 1 Reply(s)
 1239  View(s)
Rate this:

Hello dear,

I have a method that populate my class by loading an xml

public class Sample
          public void loadXML(string xmlFilePath)
                 Sample smp=new Sample();
                 smp=(Sample)s.Desserialize(reafer);   //Deserilize and populate my object from an xml file.

Now I just want to call this method from another class, so I simply have.

MyClass testObj = new MyClass();
testObj --> is EMPTY after the function returns...

Here is my question:

How can I make my current instance (testObj) filled with the data... without having to RETURN an object from my method ? (I want my method to return void)

I want it to work similarly to the NET XmlDocument class:

XmlDocument doc = new XmlDocument();
doc.Load(..) //doc is filled with data

How can I do the same thing? Dows Anybody know how to do this?

Thank you very much in advance for any help

Awadhendra Tiwari

Total Post:126

Posted on    April-16-2011 3:05 AM

We can use it following manner
public class SampleClass
 private int _myMember;
 public int MyMember
  //get and set goes here
 public void LoadXML(string xmlFilePath)
  SampleClass myObj = new SampleClass();
  myObj = SampleClasss.Deserialize(reader);
  this.MyMember = myObj .MyMeber

Modified On Apr-16-2011 03:05:58 AM

Don't want to miss updates? Please click the below button!

Follow MindStick