Pass IList <T> vs IEnumerable <T> with protobuf-net

I noticed in the protobuf-net change log that IList <> was supported, but I get the exception "Cannot instantiate interface". If I switch to IEnumerable <>, then life will be good. Does this sound right?

    // 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 a document site that has this and other answers? I hate asking new questions. :)

+3
source share
1 answer

Currently it will support IList<T>as a propertyif he does not need to create it, i.e. allow such things (attributes that are not shown for brevity):

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

, , , Merge, Deserialize ( , WCF). , , List<T>... .

- List<T>/T[] - , ... "" () , .


Re " "... google, protobuf-net (protobuf- net - " " ).

- . FAQ - ...

! ...;-p

+2

Source: https://habr.com/ru/post/1714562/


All Articles