PC Review


Reply
Thread Tools Rate Thread

Using XmlSerializer

 
 
jw56578@gmail.com
Guest
Posts: n/a
 
      6th Sep 2005
What do i need to add to my class so that the ArrayList the holds a
collection of my class will serialize properly.
heres my class

[System.Xml.Serialization.XmlInclude(typeof(Card))]
public struct Card
{
private int numbericvalue;
private CardDeck.Suits suit;
private CardDeck.Types type;


public CardDeck.Suits Suit
{
set
{
suit = value;
}
get
{
return suit;
}

}
public CardDeck.Types Type
{
set
{
type = value;
}
get
{
return type;
}

}


}

I create an ArrayList, add the class to the ArrayList and try to call
XmlSerializer.Serialiaze(myArrayList);

i recieve this error:
The type Card
was not expected.
Use the XmlInclude or SoapInclude
attribute to specify types that are not known statically

what else do i have to add to my Card class so that it will work

 
Reply With Quote
 
 
 
 
Oliver Sturm
Guest
Posts: n/a
 
      6th Sep 2005
(E-Mail Removed) wrote:

<snip>

>I create an ArrayList, add the class to the ArrayList and try to call
>XmlSerializer.Serialiaze(myArrayList);
>
>i recieve this error:
>The type Card
>was not expected.
>Use the XmlInclude or SoapInclude
>attribute to specify types that are not known statically
>
>what else do i have to add to my Card class so that it will work


You need to use the XmlInclude attribute on the collection class, not on
the object class. I think you can also use it on a property that has the
collection type, but I'm not completely sure. So, this might work:

class MyClass {
private ArrayList list;
[XmlInclude(typeof(Card))]
public ArrayList List {
get { return list; }
set { list = value; }
}
}

And I'm sure it will work if your derive your own collection type from
CollectionBase (in .NET 1, I think things are different in .NET 2 when
using a List<Card>) and put the attribute on the collection class.

Finally I should say, why didn't you post this to dotnet.xml?


Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XmlSerializer =?iso-8859-2?Q?S=B3awomir_Krzy=BFanowski?= Microsoft C# .NET 1 19th Sep 2007 08:58 PM
help using XmlSerializer =?Utf-8?B?R2FyeQ==?= Microsoft C# .NET 0 13th Apr 2006 05:43 PM
XMLSerializer Daniel Lindros via .NET 247 Microsoft C# .NET 0 13th May 2004 06:55 AM
XmlSerializer George Ter-Saakov Microsoft C# .NET 1 12th Jan 2004 10:37 PM
XMLSerializer styko Microsoft C# .NET 0 25th Sep 2003 07:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:30 PM.