1 namespace System.Activities.Presentation.View
4 using System.Collections.ObjectModel;
5 using System.ComponentModel;
7 using System.Windows.Automation.Peers;
8 using System.Windows.Input;
10 //helper class, used to resolve generics. supports cascading generic type arguments (i.e. IList< IList < int > >)
11 internal class TypeKeyValue : INotifyPropertyChanged
18 //generic's type generic parameters
19 ObservableCollection<TypeKeyValue> subTypes = new ObservableCollection<TypeKeyValue>();
22 //type resolver reference
23 Action<TypeKeyValue> typeChangedCallBack;
24 //if this type is selected
26 Func<Type, bool> filter;
27 ObservableCollection<Type> mostRecentlyUsedTypes;
28 string hintText = null;
29 //if type presenter should skip the drop down list
30 bool browseTypeDirectly = true;
32 public TypeKeyValue(Type genericType, Action<TypeKeyValue> typeChangedCallBack)
34 this.GenericType = genericType;
35 this.typeChangedCallBack = typeChangedCallBack;
38 public event PropertyChangedEventHandler PropertyChanged;
40 public string ErrorText
42 get { return this.errorText; }
45 this.errorText = value;
46 OnPropertyChanged("ErrorText");
50 public Type GenericType
52 get { return this.genericType; }
55 this.genericType = value;
56 OnPropertyChanged("GenericType");
60 public bool IsSelected
62 get { return this.isSelected; }
65 this.isSelected = value;
66 OnPropertyChanged("IsSelected");
70 public Func<Type, bool> Filter
72 get { return this.filter; }
76 OnPropertyChanged("Filter");
80 public ObservableCollection<Type> MostRecentlyUsedTypes
82 get { return this.mostRecentlyUsedTypes; }
85 this.mostRecentlyUsedTypes = value;
86 OnPropertyChanged("MostRecentlyUsedTypes");
90 public string HintText
92 get { return this.hintText; }
95 this.hintText = value;
96 this.OnPropertyChanged("HintText");
100 public bool BrowseTypeDirectly
102 get { return this.browseTypeDirectly; }
105 this.browseTypeDirectly = value;
106 OnPropertyChanged("BrowseTypeDirectly");
112 get { return this.isValid; }
115 this.isValid = value;
116 OnPropertyChanged("IsValid");
121 public ObservableCollection<TypeKeyValue> SubTypes
123 get { return this.subTypes; }
126 public Type TargetType
128 get { return this.targetType; }
131 this.targetType = value;
132 //whenever target type changes, check if there are some generic parameters required
134 OnPropertyChanged("TargetType");
135 if (typeChangedCallBack != null)
137 typeChangedCallBack(this);
142 public Type GetConcreteType()
145 if (null != this.targetType)
147 //do we have generic?
148 if (this.targetType.IsGenericTypeDefinition)
150 //resolve all generic arguments
151 Type[] arguments = new Type[this.subTypes.Count];
153 for (int i = 0; i < this.subTypes.Count && isValid; ++i)
155 arguments[i] = this.subTypes[i].GetConcreteType();
156 isValid = (null != arguments[i]);
160 //and create target type
161 result = this.targetType.MakeGenericType(arguments);
172 void LoadGenericTypes()
174 this.subTypes.Clear();
175 if (null != this.targetType && this.targetType.IsGenericTypeDefinition)
177 Type[] generics = this.targetType.GetGenericArguments();
178 foreach (Type t in generics)
180 TypeKeyValue entry = new TypeKeyValue(t, typeChangedCallBack);
181 this.subTypes.Add(entry);
182 typeChangedCallBack(entry);
187 void OnPropertyChanged(string propertyName)
189 if (null != PropertyChanged)
191 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));