How to serialize two different objects into one XML file

A

ALI-R

I have two different classes as follow and in my application I create two
diiferent objects of them and I want to srialize those two objects into one
XML file
because they are related ,Is there an suggestion on how to do that .Maybe I
need to combine these two classes and work on one class only ,right??

Thanks for your time.


Class1:
public class EnviroVars
{
private string m_reportServerName;
private string m_reportName;

public EnviroVars(){}
// Report Server Name property
public string RSName
{
get {return m_reportServerName;}
set {m_reportServerName=value;}
}
// Report Name property
public string ReportName
{
get {return m_reportName;}
set {m_reportName=value;}
}
}
============================================================================
====
Class2:

public class ReportParams
{
private ParameterValue[] m_ReportParams;
private int m_MaxReportParas;

public ReportParams(int MaxReportParas)
{
m_MaxReportParas=MaxReportParas;
m_ReportParams=new ParameterValue[MaxReportParas];
}

//Here is the implementation of the indexer by array index
public ParameterValue this[int index]
{
get
{
// Check for out of bounds condition
if ( index < 0 || index > m_ReportParams.Length- 1 )
return null;
// Return employee based on index passed in
return m_ReportParams[index];
}
set
{
// Check for out of bounds condition
if ( index < 0 || index > m_MaxReportParas - 1 )
return;
// Add new Parameter
m_ReportParams[index]= value ;
}
}

}
 
G

Guest

You may be missing what serialize does, but none the less: if you want to
make 2 classes into 1 class, then one of the classes must be a subclass of
the other and you can make them both of the class that is not a subclass. Or
you can make them into 1 class by having them both be a subclass of a common
superclass. They can both become the type of the superclass.

If you mean you want to take these 2 objects and combine them into 1 object,
then niether of these approaches will work, but rather; you will need to have
a class that has all of the compenents of both classess--a "superclass" and
make a merge merge method for the superclass to "absorbe" the subclass
objects into it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top