471,319 Members | 1,189 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

How to serialize interface???

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
3 14973
"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
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
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.

Similar topics

5 posts views Thread by David Sworder | last post: by
3 posts views Thread by Pol Bawin | last post: by
1 post views Thread by Roberto Carriquiry | last post: by
2 posts views Thread by films | last post: by
6 posts views Thread by Joe | last post: by
3 posts views Thread by Julie | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.