views:

295

answers:

2

I noticed in the protobuf-net changelog that IList<> was supported but I'm getting the "Cannot create an instance of an interface" exception. If I change to IEnumerable<> then life is good. Does this sound correct?

    // Client call
    public override IList<IApplicationWorkflow> Execute(IRoleManagement service)
    {
        IList<ApplicationWorkflowMessagePart> list = service.RetrieveWorkflows(roleNames);

        IList<IApplicationWorkflow> workflows = new List<IApplicationWorkflow>(list.Count);

        foreach (ApplicationWorkflowMessagePart a in list)
        {
            workflows.Add(new ApplicationWorkflowImpl(a));
        }

        return workflows;
    }


    // Service contract
    [OperationContract, ProtoBehavior]
    [ServiceKnownType(typeof (ServiceFault))]
    [FaultContract(typeof (ServiceFault))]
    IList<ApplicationWorkflowMessagePart> RetrieveWorkflows(string[] roleNames);


    // Service implementation
    public IList<ApplicationWorkflowMessagePart> RetrieveWorkflows(string[] roleNames)
    {
        IList<IApplicationWorkflow> workflows = manager.RetrieveApplicationWorkflows(roleNames);
        IList<ApplicationWorkflowMessagePart> workflowParts = new List<ApplicationWorkflowMessagePart>();
        if (workflows != null)
        {
            foreach (IApplicationWorkflow workflow in workflows)
            {
                workflowParts.Add(
                    ModelMediator.GetMessagePart<ApplicationWorkflowMessagePart, IApplicationWorkflow>(workflow));
            }
        }
        return workflowParts;
    }

Thanks, Mike

Also, is there document site that has this and other answers? I hate to be asking newb questions. :)

+1  A: 

Currently it will support IList<T> as a property, as long as it doesn't have to create it - i.e. allowing things like (attributes not shown for brevity):

class Order {
    private IList<OrderLine> lines = new List<OrderLine>();
    public IList<OrderLine> Lines {get {return lines;}}
}

I would have to check, but for similar reasons, I expect it would work with Merge, but not Deserialize (which is what the WCF hooks use). However, I can't think of a reason it couldn't default to List<T>... it just doesn't at the moment.

The simplest option is probably to stick with List<T> / T[] - but I can have a look if you want... but I'm in a "crunch" on a (work) project at the moment, so I can't lift the bonnet today.


Re "this and other answers"... there is a google group, but that is not just protobuf-net (protobuf-net is simply one of many "protocol buffers" implementations).

You are also free to log an issue on the project site. I do mean to collate the FAQs and add them to the wiki on the site - but time is not always my friend...

But hey! I'm here... ;-p

Marc Gravell
A: 

No worries my good man...List<> it is. Again, I appreciate the help.

Mike

Mike Battey