1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Model
7 using System.Collections.Generic;
8 using System.Collections.ObjectModel;
9 using System.ComponentModel;
10 using System.Diagnostics;
12 using System.Activities.Presentation.Model;
13 using System.Activities.Presentation.PropertyEditing;
17 // Collection of ModelPropertyEntries used to model sub-properties of PropertyValues
19 internal class ModelPropertyEntryCollection : PropertyEntryCollection
22 List<ModelPropertyEntry> _properties;
27 // <param name="parentProperty">Parent property</param>
28 public ModelPropertyEntryCollection(ModelPropertyEntry parentProperty)
29 : base(parentProperty.PropertyValue)
32 CreateCollection(parentProperty);
38 // <param name="parentProperty">Parent indexer</param>
39 public ModelPropertyEntryCollection(ModelPropertyIndexer parentProperty)
40 : base(parentProperty.PropertyValue)
43 CreateCollection(parentProperty);
47 // Gets the number of PropertyEntries in this collection
49 public override int Count
52 return _properties == null ? 0 : _properties.Count;
57 // Gets the property from this collection of the given name (case sensitive)
59 // <param name="propertyName">Name to look up</param>
60 // <returns>Corresponding PropertyEntry if one exists.</returns>
61 public override PropertyEntry this[string propertyName] {
63 if (_properties == null)
68 foreach (ModelPropertyEntry entry in _properties)
70 if (string.Equals(entry.PropertyName, propertyName))
81 // Gets the enumerator for this collection
83 // <returns></returns>
84 public override IEnumerator<PropertyEntry> GetEnumerator()
86 if (_properties == null)
91 for (int i = 0; i < _properties.Count; i++)
93 yield return _properties[i];
97 // Parses the sub-properties of the given parent collection item and populates a corresponding
98 // private list of ModelPropertyEntries that represents it.
99 private void CreateCollection(ModelPropertyIndexer parentCollectionItem)
102 // Assert some assumptions that should be true at this point
103 Fx.Assert(parentCollectionItem.ModelItem != null, "parentCollectionItem.ModelItem should not be null");
105 List<ModelProperty> subProperties = ExtensibilityAccessor.GetSubProperties(parentCollectionItem.ModelItem);
107 if (subProperties == null || subProperties.Count < 1)
112 // At this point we have at least one ModelProperty that acts as a subProperty of the
113 // given ModelItem. Wrap the list in ModelPropertyEntries and exit.
115 _properties = new List<ModelPropertyEntry>(subProperties.Count);
117 for (int i = 0; i < subProperties.Count; i++)
119 _properties.Add(new ModelPropertyEntry(subProperties[i], (ModelPropertyValue)parentCollectionItem.PropertyValue));
122 // Sort the sub-properties by their OrderToken as well as their name
123 if (_properties != null)
129 private void CreateCollection(ModelPropertyEntry parentProperty)
132 // Assert some assumptions that should be true at this point
133 Fx.Assert(parentProperty != null, "parentProperty should not be null");
134 Fx.Assert(parentProperty.ModelPropertySet != null, "parentProperty.ModelPropertySet should not be null");
135 Fx.Assert(parentProperty.ModelPropertySet.Count > 0, "parentProperty.ModelPropertySet.Count should be > 0");
137 // Ignore sub-properties of MarkupExtensions for v1
138 if (parentProperty.IsMarkupExtension)
143 IEnumerable<IList<ModelProperty>> mergedSubProperties = ModelPropertyMerger.GetMergedSubProperties(parentProperty.ModelPropertySet);
146 bool multiSelect = parentProperty.ModelPropertySet.Count > 1;
147 foreach (IList<ModelProperty> subPropertySet in mergedSubProperties)
152 _properties = new List<ModelPropertyEntry>();
155 ModelPropertyEntry entry;
159 entry = new ModelPropertyEntry(subPropertySet, (ModelPropertyValue)parentProperty.PropertyValue);
163 entry = new ModelPropertyEntry(subPropertySet[0], (ModelPropertyValue)parentProperty.PropertyValue);
166 _properties.Add(entry);
170 // Sort the sub-properties by their OrderToken as well as their name
171 if (_properties != null)