How to serialize interface???

M

Mirek Endys

What is the best way to serialize object, that contains data in interfaces.
Simple. I have instance of my object, that contains data in interfaces.
What is the best way to XMLSerialize and deserialize this object?

Thanks.
 
J

Joanna Carter [TeamB]

"Mirek Endys" <[email protected]> a écrit dans le message de [email protected]...

| What is the best way to serialize object, that contains data in
interfaces.
| Simple. I have instance of my object, that contains data in interfaces.
| What is the best way to XMLSerialize and deserialize this object?

You can't serialise an interface because it doesn't contain any data. You
say that your object contains data in interfaces; in fact, it has to contain
objects or at least methods that implement the interfaces. You have to
serialise the objects that implement the interfaces

Joanna
 
M

Mirek Endys

Thanks Joana,

I know basics about serialization and interfaces, but I have this problem:
I serialize this object

class MyClass
{


private IDataParameterCollection _SelectParameters = null;

[XmlArray("selectParams")]
[XmlArrayItem(typeof(iDB2Parameter))]
[XmlArrayItem(typeof(SqlParameter))]
public List<object> SelectParams
{
get
{
List<object> list = new List<object>();
if(this._SelectParameters != null)
foreach(object oneParam in this._SelectParameters)
list.Add(oneParam);
return list;
}
set
{

foreach(object oneParam in value)
this._SelectParameters.Add(oneParam);
}
}
}


if I serialize this, in the xml file i have:

- <selectParams>
- <iDB2Parameter>
<DbType>String</DbType>
<iDB2DbType>iDB2VarGraphic</iDB2DbType>
<Direction>Input</Direction>
<IsNullable>false</IsNullable>
<ParameterName>DRSY</ParameterName>
<SourceColumn />
<SourceVersion>Current</SourceVersion>
<Precision>0</Precision>
<Scale>0</Scale>
<Size>0</Size>
<Value xsi:type="xsd:string">01</Value>
</iDB2Parameter>
- <iDB2Parameter>
<DbType>String</DbType>
<iDB2DbType>iDB2VarGraphic</iDB2DbType>
<Direction>Input</Direction>
<IsNullable>false</IsNullable>
<ParameterName>DRRT</ParameterName>
<SourceColumn />
<SourceVersion>Current</SourceVersion>
<Precision>0</Precision>
<Scale>0</Scale>
<Size>0</Size>
<Value xsi:type="xsd:string">03</Value>
</iDB2Parameter>
</selectParams>


BUT!!! I cannot deserialize it. The all properties are desirialized well,
but this 'selectParams' are 'null'.
How to deserialize this???


Thanks.
 
Y

Yuan Ren[MSFT]

Hi,

Thanks for posting!

I'm sorry for late response since I had a bad cold yesterday. From your
description, I have performed a test with the current class. The type of
serialization is XML serialization. Since I don't have a instance of the
current class, I can not perform the issue. The following snippet if my
code of serialization:

=======
private static void MySerialize(string filename)
{
XmlSerializer ser = new XmlSerializer(typeof(MyClass));
MyClass myClass = new MyClass();
myClass.SelectParams.Add("Test");
TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, myClass);
writer.Close();
}

=======

Unfortunately, I can not repro the current issue. Could you please more
details about the current issue? I appreciate your understanding!

I'm looking forward your reply.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006. Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 

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