1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.View
7 using System.Collections.ObjectModel;
8 using System.Diagnostics.CodeAnalysis;
9 using System.Collections.Generic;
11 [Fx.Tag.XamlVisible(false)]
12 public class TypeResolvingOptions
14 private IDictionary<string, string> hintTextMap;
16 public TypeResolvingOptions() : this(null)
20 public TypeResolvingOptions(IEnumerable<Type> defaultTypes)
22 if (defaultTypes != null)
24 this.MostRecentlyUsedTypes = new ObservableCollection<Type>();
25 foreach (Type item in defaultTypes)
29 throw FxTrace.Exception.AsError(new ArgumentException(SR.TypeResolvingOptionsArgumentExceptionMessage));
31 this.MostRecentlyUsedTypes.Add(item);
36 public Func<Type, bool> Filter
42 [SuppressMessage(FxCop.Category.Usage, FxCop.Rule.CollectionPropertiesShouldBeReadOnly,
43 Justification = "Setter is provided to data binding on this property.")]
44 internal ObservableCollection<Type> MostRecentlyUsedTypes
51 /// A dictionary that maps the name of a generic type argument to a hint text.
53 internal IDictionary<string, string> HintTextMap
57 if (this.hintTextMap == null)
59 this.hintTextMap = new Dictionary<string, string>();
62 return this.hintTextMap;
66 public bool BrowseTypeDirectly
72 internal static TypeResolvingOptions Merge(TypeResolvingOptions lhs, TypeResolvingOptions rhs)
83 TypeResolvingOptions result = new TypeResolvingOptions
85 Filter = FuncAnd(lhs.Filter, rhs.Filter),
86 MostRecentlyUsedTypes = Intersect(lhs.MostRecentlyUsedTypes, rhs.MostRecentlyUsedTypes),
87 BrowseTypeDirectly = lhs.BrowseTypeDirectly && rhs.BrowseTypeDirectly
90 // Pass in the fields directly to prevent triggering lazy initialization.
91 IDictionary<string, string> mergedHintTextMap = MergeDictionaries<string, string>(lhs.hintTextMap, rhs.hintTextMap);
92 if (mergedHintTextMap != null && mergedHintTextMap.Count > 0)
94 foreach (KeyValuePair<string, string> kvp in mergedHintTextMap)
96 result.HintTextMap.Add(kvp.Key, kvp.Value);
103 static Func<Type, bool> FuncAnd(Func<Type, bool> lhs, Func<Type, bool> rhs)
109 else if (rhs == null)
114 return new Func<Type, bool>((e) => lhs(e) && rhs(e));
117 static ObservableCollection<T> Intersect<T>(ObservableCollection<T> lhs, ObservableCollection<T> rhs)
123 else if (rhs == null)
128 ObservableCollection<T> collection = new ObservableCollection<T>();
140 static IDictionary<TKey, TValue> MergeDictionaries<TKey, TValue>(IDictionary<TKey, TValue> lhs, IDictionary<TKey, TValue> rhs)
142 if (lhs == null || lhs.Count == 0)
147 if (rhs == null || rhs.Count == 0)
152 Dictionary<TKey, TValue> result = new Dictionary<TKey, TValue>();
153 foreach (KeyValuePair<TKey, TValue> kvp in lhs)
155 result.Add(kvp.Key, kvp.Value);
158 foreach (KeyValuePair<TKey, TValue> kvp in rhs)
160 if (!result.ContainsKey(kvp.Key))
162 result.Add(kvp.Key, kvp.Value);