[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / State / AggregateStateContainer.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.State 
5 {
6     using System;
7     using System.Diagnostics;
8
9     // <summary>
10     // Aggregate of IStateContainer objects
11     // </summary>
12     internal class AggregateStateContainer : IStateContainer 
13     {
14
15         private IStateContainer[] _containers;
16
17         public AggregateStateContainer(params IStateContainer[] containers) {
18             _containers = containers;
19         }
20
21         public object RetrieveState() 
22         {
23             object[] states = null;
24
25             if (_containers != null) 
26             {
27                 states = new object[_containers.Length];
28                 for (int i = 0; i < _containers.Length; i++)
29                 {
30                     states[i] = _containers[i] == null ? null : _containers[i].RetrieveState();
31                 }
32             }
33
34             return states;
35         }
36
37         public void RestoreState(object state) 
38         {
39             if (_containers != null) 
40             {
41
42                 object[] states = state as object[];
43                 if (states == null || states.Length != _containers.Length) 
44                 {
45                     Debug.Fail("Invalid state to restore: " + (state == null ? "null" : state.ToString()));
46                     return;
47                 }
48
49                 for (int i = 0; i < _containers.Length; i++)
50                 {
51                     if (_containers[i] != null)
52                     {
53                         _containers[i].RestoreState(states[i]);
54                     }
55                 }
56             }
57         }
58     }
59 }