Serializing an enum variable

P

Pedro

Hello,

Here's a piece of code that i have which is giving me an error and im not
sure how to fix it.
I'm trying to serialize an enum variable wich a value outside of the enum
list and the serializer throws an error saying its an invalid value (of
course). But how toget around it?

Public Class foo

Public Enum Nums
Zero = 0
One = 1
Two = 2
Four = 4
End Enum

Public MyNum = Two Or Four (this would result on a number 6)

End Class

I would like to be able to serialize the number, not so much the actual
text.
I've tried <xmlInclude(gettype(Integer)> but it says that primitive types
are not allowed.


Any ideas?


Thanks
 
P

Pedro

Thanks alot for the help Nicole

The result im getting is now the XML containing the actual names
resulting in:

<Nums>Two Four</Nums>

So i'm getting the actual enum names space separated.
What I would like is the actual number instead for AND bitwising.
I dont suppose you know how to do this?


Thanks
Pedro
 
N

Nicole Calinoiu

If you want to render the bitwise ORed result, your best bet would
presumably be to expose that result cast to an integer (or whatever your
enum's underlying type might be). One can control the rendered value for an
enum using XmlEnumAttribute, but that won't change the rendering of separate
values for a flags enum.
 

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