ProtoInclude for fields ?

Posted by Big on Stack Overflow See other posts from Stack Overflow or by Big
Published on 2009-09-24T15:24:22Z Indexed on 2010/05/13 13:04 UTC
Read the original article Hit count: 281

Filed under:
|
|

I have a simple object

[ProtoContract]
public class DataChangedEventArgs<T> : EventArgs
{
    private readonly object key;
    private readonly T data;
    private readonly DataChangeType changeType;

    ///<summary>
    /// Key to identify the data item
    ///</summary>
    public object Key
    {
        get { return key; }
    }

    [ProtoMember(2, IsRequired = true)]
    public T Data
    {
        get { return data; }
    }

    [ProtoMember(3, IsRequired = true)]
    public DataChangeType ChangeType
    {
        get { return changeType; }
    }

and I have a problem with the key. Its type is object, but it can be either int, long or string. I would intuitively use a ProtoInclude attribute to say "expect these types" but unfortunately they are class only attribute. Does anybody has any idea how I could work around this ? For background, the public object Key is here for historical reasons (and all over the place) so I would very much like to avoid the mother of all refactorings ;-) Any chance I could get this to Serialize, even force it to Serialize as a string ?

© Stack Overflow or respective owner

Related posts about protocol-buffers

Related posts about c#