Ask for Collections samples!

Mar 18, 2008 at 6:58 AM
Hi all,

I think Collections (both readonly collections and not) are very common case in Object Model. Could you please add some sample for it?
I can't find any resource on it from MSDN and internet. :(

Please please think it seriously and do me a favor :(

Mar 18, 2008 at 9:25 PM
We don't have a sample that was specifically built to demo collections but several of them have examples of how to use collections. Take a look at the WPF Calculator sample here: Sample- WPF Caclulator

You can take a quick look at the source online without even downloading the sample:
You'll see in the contract for this sample there is the following interfaces:
   public interface IVisualCalculatorContract : IContract
       IListContract<IOperationContract> GetOperations();
       System.AddIn.Contract.INativeHandleContract Operate(IOperationContract op, double[] operands);
       string GetName();
   public interface IOperationContract : IContract
       string GetName();
       int GetNumOperands();

In those interfaces the add-in is returning an IListContract<IOperationContract> to the host. In the add-in and host view that gets represented as IList<IOperation>.

In this case we are showing a contract representation of IList<T> and the actual type the add-in uses is List<IOperation>. The add-in instead could have instantiated a ReadOnlyCollection<T> (which implements IList<T>) and if it had done so it would end up having read-only semantics. You can download the sample, modify the code a bit, and give it a try.

Let me know if you have any other questions about this.