/// <summary> /// Launch the user interface for developer to pick a contract type. /// </summary> /// <param name="localAssemblyName">The local assembly name.</param> /// <param name="referencedAssemblies">The list of referenced assembly names.</param> /// <param name="editingContext">The editing context.</param> /// <returns>The contract type selected by user or null if user cancels.</returns> public static Type SelectContractType(AssemblyName localAssemblyName, IList<AssemblyName> referencedAssemblies, EditingContext editingContext) { AssemblyContextControlItem assemblyContextControlItem = new AssemblyContextControlItem { LocalAssemblyName = localAssemblyName, ReferencedAssemblyNames = referencedAssemblies }; TypeBrowser typeBrowser = new TypeBrowser(assemblyContextControlItem, editingContext, FilterFunction); bool? dialogResult = typeBrowser.ShowDialog(/* owner = */ null); if (dialogResult.HasValue && dialogResult.Value) { return typeBrowser.ConcreteType; } else { return null; } }
public TypeBrowserAutomationPeer(TypeBrowser owner) : base(owner) { }
// return true if KeyDownEvent should be set to handled bool HandleBrowseType() { bool retval = false; TypeWrapper wrapper = (TypeWrapper)this.typeComboBox.SelectedItem; if ((wrapper != null && !wrapper.IsTypeDefinition) || this.BrowseTypeDirectly) { Type result = null; bool?dialogResult = true; bool typeIsArray = true; bool fireEvent = false; //handle choosing an array of T if (wrapper != null && typeof(ArrayOf <>) == wrapper.Type) { fireEvent = true; this.RaiseEvent(new RoutedEventArgs(TypePresenter.TypeBrowserOpenedEvent, this)); result = wrapper.Type; } else if (wrapper != null && wrapper.DisplayName == NullString) { this.Type = null; return(false); } else { retval = true; fireEvent = true; this.RaiseEvent(new RoutedEventArgs(TypePresenter.TypeBrowserOpenedEvent, this)); TypeBrowser browser = new TypeBrowser(AssemblyContext, this.Context, this.Filter); SetWindowOwner(browser); if (this.CenterTypeBrowserDialog) { browser.WindowStartupLocation = WindowStartupLocation.CenterScreen; } dialogResult = browser.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value) { result = browser.ConcreteType; } typeIsArray = false; } if (dialogResult.HasValue && dialogResult.Value) { //user may have chosen generic type (IList) if (result.IsGenericTypeDefinition) { retval = true; ActivityTypeResolver wnd = new ActivityTypeResolver(); SetWindowOwner(wnd); wnd.Context = this.Context; wnd.EditedType = result; if (this.CenterActivityTypeResolverDialog) { wnd.WindowStartupLocation = WindowStartupLocation.CenterScreen; } result = (true == wnd.ShowDialog() ? wnd.ConcreteType : null); } //if we have a type if (null != result) { //if we have a ArrayOf<some type here>, create actual array type if (typeIsArray) { result = result.GetGenericArguments()[0].MakeArrayType(); } //add it to the cache if (!MostRecentlyUsedTypes.Any <Type>(p => Type.Equals(p, result))) { MostRecentlyUsedTypes.Add(result); } //and return updated result this.Type = result; } else { this.Type = this.lastSelection; } BindingExpression binding = this.typeComboBox.GetBindingExpression(ComboBox.SelectedItemProperty); binding.UpdateTarget(); } else { SetComboBoxToLastSelection(); } if (fireEvent) { this.RaiseEvent(new RoutedEventArgs(TypePresenter.TypeBrowserClosedEvent, this)); } } return(retval); }