Home Forums Support What's the best way to send a collection of objects?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4084
    Anonymous
    Inactive

    Hi, I’m new NetworkComms.net and so far, I really like it.

    I need to send a collection of objects. Basically a file list.

    So I created a FileDetails object
    [ProtoContract]
    [JsonObject(MemberSerialization.OptIn)]
    public class FileDetails
    {
    [ProtoMember(1)]
    [JsonProperty]
    public string FileName { get; set; }

    }

    but I don’t know the best way to send a List<FileDetails> or honestly ANY way to send them.

    I tried

    public List<FileDetails> _files;
    [ProtoMember(4, OverwriteList = true)]
    private IEnumerable<FileDetails> Files
    {
    get { return _files; }
    set
    {
    _files = new List<FileDetails>();
    _files.AddRange(value);
    }
    }

    but when I sent the message, the connection at the other end closes.

    I looked thru your sample code and didn’t find a collection inside a message anywhere.

    Can you point me in the right direction?

    thanks

    #4085
    Anonymous
    Inactive

    I found the answer. Don’t use collections, use plain old arrays ([])
    http://stackoverflow.com/questions/10510589/how-to-serialize-arrays

    here’s an example:
    [ProtoMember(4)]
    [JsonProperty]
    public FileDetails[] Files;

    hope it helps others. 🙂

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.