By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,003 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

How to serialize interface???

P: n/a
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.
Feb 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Mirek Endys" <Mi****@community.nospam> a écrit dans le message de news:
uj**************@TK2MSFTNGP12.phx.gbl...

| 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

--
Joanna Carter [TeamB]
Consultant Software Engineer
Feb 23 '06 #2

P: n/a
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.

"Joanna Carter [TeamB]" <jo****@not.for.spam> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Mirek Endys" <Mi****@community.nospam> a écrit dans le message de news:
uj**************@TK2MSFTNGP12.phx.gbl...

| 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

--
Joanna Carter [TeamB]
Consultant Software Engineer

Feb 23 '06 #3

P: n/a
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.
================================================== ====

Mar 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.