views:

28

answers:

1

Long story short, I have a struct (see below) that contains exactly one field:

private int value;

I've also implemented implicit conversion operators:

    public static implicit operator int(Outlet val)
    {
        return val.value;
    }

    public static implicit operator Outlet(int val)
    {
        return new Outlet(val);
    }

I've implemented all of the following :

IComparable, IComparable<Cart>, IComparable<int>, IConvertible, IEquatable<Cart>, IEquatable<int>, IFormattable

I'm at a point where I really have no clue why, but whenever I serialize this object, I get no value. For instance, with XmlSerialization:

<Outlet />

Also, I'm not solely concerned about XmlSerialization, I'm concerned about ALL serialization (binary for instance) How can I ensure that this serializes properly?

NOTE: I did this because mapping an int,int dictionary seemed rather poorly typed to me when explicit objects with validation behavior were desired.

+1  A: 

XML serialization only works with public properties, so you would need to expose a public property that sets/gets the value.

As an alternative, you can implement IXmlSerializable to manually serialise the structure.

This is only an issue with XML serialisation. The binary serialiser will serialise private fields as well as public ones.

Dean Harding
I was aware of the public limitation, but wasn't aware IXmlSerializable provided a way around this. Thank you.
Firoso
Still having some wierdness however. it's only wanting to serialize my very first value the first time it hits it, for instance, <Slot>1</Slot> <Outlet>1</Outlet>I only get Slot = 1, and outlet is never set (same basic code)
Firoso