That was exactly my thought. Something *broadly* like (untested):

    [ProtoMember(1)]
    public List<Foo> Foos {get;set;}

    [ProtoMember(2), DefaultValue(false)]
    private bool FoosHasValue {
        get { return Foos != null; }
        set { Foos = value ? ( Foos ?? new List<Foo>() ) : null; }
    }

Note that this may have some impact if you are concatenating messages, and
is slightly hacky - Kenton will be tutting, I expect ;p

Marc

On 22 June 2010 21:25, Manh Do <[email protected]> wrote:

> What are your suggestions? One option that I was thinking is to add a
> boolean field in the message that determines if the list is empty or
> not. What do you think?
>
> On Jun 22, 1:21 pm, Marc Gravell <[email protected]> wrote:
> > Kenton is of course quite correct. There is no *native* distinction
> between
> > a null list and an empty list in the raw protobuf data stream. There
> *are*
> > some ways of working around that, to distinguish between the two, but not
> > when using the code-generation from .proto.
> >
> > Marc
> >
> > On 22 June 2010 18:59, Kenton Varda <[email protected]> wrote:
> >
> >
> >
> >
> >
> > > Protocol Buffers has no concept of "null".  Lists can be empty, but not
> > > "null".
> >
> > > On Mon, Jun 21, 2010 at 6:35 PM, Manh Do <[email protected]> wrote:
> >
> > >> I am working a project where we need to determine if a protobuf list
> > >> have is null or not in the protocol buffer.
> >
> > >> The problem is the generated c# automatically instantiates the list.
> >
> > >> IE. Protocol:
> > >> message B {
> > >>  repeated A MyList = 0;
> > >> }
> >
> > >> Generated C#:
> >
> > >> private readonly global::System.Collections.Generic.List<A> _MyList =
> > >> new global::System.Collections.Generic.List<A>();
> > >>    [global::ProtoBuf.ProtoMember(0, Name=@"MyList", DataFormat =
> > >> global::ProtoBuf.DataFormat.Default)]
> > >>    public global::System.Collections.Generic.List<A> MyList
> > >>    {
> > >>      get { return _MyList ; }
> > >>    }
> >
> > >> The problem with this is I cannot determine if the list is null. I am
> > >> using an empty list as a way to remove all objects.
> >
> > >> Is there a way where I can make the generator not automatically
> > >> instantiate the list? Better yet, how do I check for default values in
> > >> protocol buffer C#? I know you can check for
> > >> 'default(typeof(MyType));'.
> >
> > >> Thanks for the help!
> >
> > >> -Manh
> >
> > >> --
> > >> You received this message because you are subscribed to the Google
> Groups
> > >> "Protocol Buffers" group.
> > >> To post to this group, send email to [email protected].
> > >> To unsubscribe from this group, send email to
> > >> [email protected]<protobuf%[email protected]>
> <protobuf%[email protected] om>
> > >> .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/protobuf?hl=en.
> >
> > >  --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Protocol Buffers" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected]<protobuf%[email protected]>
> <protobuf%[email protected] om>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/protobuf?hl=en.
> >
> > --
> > Regards,
> >
> > Marc
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<protobuf%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>


-- 
Regards,

Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to