protected override Type GetSelectedType(Type selectedType, Type baseType, TypeSelectorIncludes selectorIncludes, Type configurationType)
 {
     BaseTypeRequested = baseType;
     SelectedTypeRequested = selectedType;
     SelectedTypeIncludes = selectorIncludes;
     return ExceptionTypeUsed;
 }
예제 #2
0
 protected override Type GetSelectedType(Type selectedType, Type baseType, TypeSelectorIncludes selectorIncludes, Type configurationType)
 {
     BaseTypeRequested     = baseType;
     SelectedTypeRequested = selectedType;
     SelectedTypeIncludes  = selectorIncludes;
     return(ExceptionTypeUsed);
 }
        private Type GetSelectedType()
        {
            Type baseType                 = typeof(object);
            Type configurationType        = null;
            TypeSelectorIncludes includes = TypeSelectorIncludes.None;

            PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(ConfigurationElementType).Find(propertyToSet,
                                                                                                                true);

            if (propertyDescriptor == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Could not find property {0} on configuration element type {1}", propertyToSet, ConfigurationElementType.Name));
            }

            BaseTypeAttribute baseTypeAttribute = propertyDescriptor.Attributes.OfType <BaseTypeAttribute>().FirstOrDefault();

            if (baseTypeAttribute != null)
            {
                baseType          = baseTypeAttribute.BaseType;
                includes          = baseTypeAttribute.TypeSelectorIncludes;
                configurationType = baseTypeAttribute.ConfigurationType;
            }

            return(GetSelectedType(baseType, baseType, includes, configurationType));
        }
예제 #4
0
 /// <summary>
 /// <para>Initialize a new instance of the <see cref="TypeSelectorUI"/> class.</para>
 /// </summary>
 /// <param name="currentType">
 /// <para>The current <see cref="Type"/> selected.</para>
 /// </param>
 /// <param name="baseType">
 /// <para>The <see cref="Type"/> to filter and verify when loading.</para>
 /// </param>
 /// <param name="flags">
 /// <para>The flags for the editor.</para>
 /// </param>
 /// <param name="configurationType"></param>
 public TypeSelectorUI(Type currentType, Type baseType, TypeSelectorIncludes flags, Type configurationType) : this()
 {
     this.openFileDialog.DereferenceLinks = false;
     this.selector = new TypeSelector(currentType, baseType, flags, configurationType, this.treeView);
     this.treeView.Select();
     this.Text += baseType.FullName;
 }
예제 #5
0
        /// <summary>
        /// <para>Initialize a new instance of the <see cref="TypeSelectorUI"/> class.</para>
        /// </summary>
        /// <param name="currentType">
        /// <para>The current <see cref="Type"/> selected.</para>
        /// </param>
        /// <param name="baseType">
        /// <para>The <see cref="Type"/> to filter and verify when loading.</para>
        /// </param>
        /// <param name="flags">
        /// <para>The flags for the editor.</para>
        /// </param>
		/// <param name="configurationType"></param>
        public TypeSelectorUI(Type currentType, Type baseType, TypeSelectorIncludes flags, Type configurationType) : this()
        {
            this.openFileDialog.DereferenceLinks = false;
            this.selector = new TypeSelector(currentType, baseType, flags, configurationType, this.treeView);
            this.treeView.Select();
            this.Text += baseType.FullName;
        }
        public void ExcludeAllInterfacesTest()
        {
            TypeSelectorIncludes flags    = TypeSelectorIncludes.None;
            TypeSelector         selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, treeView);
            bool valid = selector.IsTypeValid(typeof(IComparable));

            Assert.IsFalse(valid);
        }
        public void ExcludeNonPublicTypes()
        {
            TypeSelectorIncludes flags    = TypeSelectorIncludes.None;
            TypeSelector         selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, treeView);
            bool valid = selector.IsTypeValid(typeof(NonPublicClass));

            Assert.IsFalse(valid);
        }
        public void ExcludeBaseTypeTest()
        {
            TypeSelectorIncludes flags    = TypeSelectorIncludes.None;
            TypeSelector         selector = new TypeSelector(null, typeof(Exception), flags, treeView);
            bool valid = selector.IsTypeValid(typeof(Exception));

            Assert.IsFalse(valid);
        }
        public void ExcludeAbstractTypesTest()
        {
            TypeSelectorIncludes flags    = TypeSelectorIncludes.None;
            TypeSelector         selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, treeView);
            bool valid = selector.IsTypeValid(typeof(Stream));

            Assert.IsFalse(valid);
        }
 /// <summary>
 /// Initializes a new instance of the  <see cref="BaseTypeAttribute"/> class with the specified base <see cref="Type"/> object and configuration <see cref="Type"/>.
 /// </summary>
 /// <param name="typeSelectorIncludes">
 /// One of the <see cref="typeSelectorIncludes"/> values.
 /// </param>
 /// <param name="baseType">The base <see cref="Type"/> to filter.</param>
 /// <param name="configurationType">The configuration object <see cref="Type"/>.</param>
 public BaseTypeAttribute(Type baseType, TypeSelectorIncludes typeSelectorIncludes, Type configurationType)
     : base()
 {
     if (null == baseType) throw new ArgumentNullException("baseType");
     this.configurationType = configurationType;
     this.baseType = baseType;
     this.typeSelectorIncludes = typeSelectorIncludes;
 }
        public void ExcludeTypesWithoutConfigurationElementType()
        {
            TypeSelectorIncludes flags    = TypeSelectorIncludes.None;
            TypeSelector         selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, typeof(TestConfigurationElement), treeView);
            bool valid = selector.IsTypeValid(typeof(ITest));

            Assert.IsFalse(valid);
        }
        public void IncludeTypesWithConfigurationElementType()
        {
            TypeSelectorIncludes flags    = TypeSelectorIncludes.None;
            TypeSelector         selector = new TypeSelector(null, typeof(ITest), flags, typeof(TestConfigurationElement), treeView);
            bool valid = selector.IsTypeValid(typeof(TestWithConfigurationType));

            Assert.IsTrue(valid);
        }
        public void IncludeAbstractTypesTest()
        {
            TypeSelectorIncludes flags    = TypeSelectorIncludes.AbstractTypes;
            TypeSelector         selector = new TypeSelector(null, typeof(ITest), flags, treeView);
            bool valid = selector.IsTypeValid(typeof(AbstractTest));

            Assert.IsTrue(valid);
            valid = selector.IsTypeValid(typeof(ITest2));
            Assert.IsTrue(valid);
        }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the  <see cref="BaseTypeAttribute"/> class with the specified base <see cref="Type"/> object and configuration <see cref="Type"/>.
 /// </summary>
 /// <param name="typeSelectorIncludes">
 /// One of the <see cref="typeSelectorIncludes"/> values.
 /// </param>
 /// <param name="baseType">The base <see cref="Type"/> to filter.</param>
 /// <param name="configurationType">The configuration object <see cref="Type"/>.</param>
 public BaseTypeAttribute(Type baseType, TypeSelectorIncludes typeSelectorIncludes, Type configurationType)
     : base()
 {
     if (null == baseType)
     {
         throw new ArgumentNullException("baseType");
     }
     this.configurationType    = configurationType;
     this.baseType             = baseType;
     this.typeSelectorIncludes = typeSelectorIncludes;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TypeBuildNodeConstraint"/> class.
        /// </summary>
        /// <param name="baseType">The base type (class or interface) from which the constrained type should derive.</param>
        /// <param name="configurationType">The base type from which a type specified by the
        /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementTypeAttribute"/>
        /// bound to the constrained type should derive, or <see langword="null"/> if no such constraint is necessary.
        /// </param>
        /// <param name="typeSelectorIncludes">Additional constraints.</param>
        public TypeBuildNodeConstraint(
            Type baseType,
            Type configurationType,
            TypeSelectorIncludes typeSelectorIncludes)
        {
            this.BaseType             = baseType;
            this.ConfigurationType    = configurationType;
            this.TypeSelectorIncludes = typeSelectorIncludes;

            includeAbstractTypes  = IsSet(TypeSelectorIncludes.AbstractTypes);
            includeInterfaces     = IsSet(TypeSelectorIncludes.Interfaces);
            includeNonPublicTypes = IsSet(TypeSelectorIncludes.NonpublicTypes);
            includeBaseType       = IsSet(TypeSelectorIncludes.BaseType);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TypeBuildNodeConstraint"/> class.
        /// </summary>
        /// <param name="baseType">The base type (class or interface) from which the constrained type should derive.</param>
        /// <param name="configurationType">The base type from which a type specified by the 
        /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementTypeAttribute"/>
        /// bound to the constrained type should derive, or <see langword="null"/> if no such constraint is necessary.
        /// </param>
        /// <param name="typeSelectorIncludes">Additional constraints.</param>
        public TypeBuildNodeConstraint(
            Type baseType,
            Type configurationType,
            TypeSelectorIncludes typeSelectorIncludes)
        {
            this.BaseType = baseType;
            this.ConfigurationType = configurationType;
            this.TypeSelectorIncludes = typeSelectorIncludes;

            includeAbstractTypes = IsSet(TypeSelectorIncludes.AbstractTypes);
            includeInterfaces = IsSet(TypeSelectorIncludes.Interfaces);
            includeNonPublicTypes = IsSet(TypeSelectorIncludes.NonpublicTypes);
            includeBaseType = IsSet(TypeSelectorIncludes.BaseType);
        }
        /// <summary>
        /// Retrieves and returns the selected type from the user.
        /// </summary>
        /// <param name="selectedType">The type to select in the type selection dialog.</param>
        /// <param name="baseType">The base type (class or interface) from which the constrained type should derive.</param>
        /// <param name="selectorIncludes">Indicates the types that can be browsed.</param>
        /// <param name="configurationType">The base type from which a type specified by the
        /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementTypeAttribute"/>
        /// bound to the constrained type should derive, or <see langword="null"/> if no such constraint is necessary.
        /// </param>
        /// <returns>
        /// The selected <see cref="Type"/> or <see langword="null"/> if not type is selected.
        /// </returns>
        protected virtual Type GetSelectedType(Type selectedType, Type baseType, TypeSelectorIncludes selectorIncludes, Type configurationType)
        {
            var viewModel = new TypeBrowserViewModel(new TypeBuildNodeConstraint(baseType, configurationType, selectorIncludes), this);
            var selector  = new TypeBrowser(viewModel, this.discoveryService);

            Nullable <bool> result = false;

            if (this.UIService != null)
            {
                result = UIService.ShowDialog(selector);
            }
            else
            {
                result = selector.ShowDialog();
            }

            if (result.HasValue && result.Value)
            {
                return(selector.SelectedType);
            }
            return(null);
        }
예제 #18
0
		public TypeSelector(Type currentType, Type baseType, TypeSelectorIncludes flags, Type configurationType, TreeView treeView)
        {
            if (treeView == null)
            {
                throw new ArgumentNullException("treeView");
            }
            if (baseType == null)
            {
                throw new ArgumentNullException("typeToVerify");
            }
            loadedAssemblies = new Hashtable();
            this.configurationType = configurationType;
            this.treeView = treeView;
            this.currentType = currentType;
            this.baseType_ = baseType;
            this.flags = flags;
            this.includeAbstractTypes = IsSet(TypeSelectorIncludes.AbstractTypes);
            this.includeAllInterfaces = IsSet(TypeSelectorIncludes.Interfaces);
            this.includeNonPublicTypes = IsSet(TypeSelectorIncludes.NonpublicTypes);
            this.includeBaseType = IsSet(TypeSelectorIncludes.BaseType);

            LoadTypes(baseType);
        }
예제 #19
0
        public TypeSelector(Type currentType, Type baseType, TypeSelectorIncludes flags, Type configurationType, TreeView treeView)
        {
            if (treeView == null)
            {
                throw new ArgumentNullException("treeView");
            }
            if (baseType == null)
            {
                throw new ArgumentNullException("typeToVerify");
            }
            loadedAssemblies           = new Hashtable();
            this.configurationType     = configurationType;
            this.treeView              = treeView;
            this.currentType           = currentType;
            this.baseType_             = baseType;
            this.flags                 = flags;
            this.includeAbstractTypes  = IsSet(TypeSelectorIncludes.AbstractTypes);
            this.includeAllInterfaces  = IsSet(TypeSelectorIncludes.Interfaces);
            this.includeNonPublicTypes = IsSet(TypeSelectorIncludes.NonpublicTypes);
            this.includeBaseType       = IsSet(TypeSelectorIncludes.BaseType);

            LoadTypes(baseType);
        }
예제 #20
0
 public TypeSelector(Type currentType, Type baseType, TypeSelectorIncludes flags, TreeView treeView)
     : this(currentType, baseType, flags, null, treeView)
 {
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTypeAttribute"/> class with the specified <see cref="Type"/> object and <see cref="TypeSelectorIncludes"/>.
 /// </summary>
 /// <param name="baseType">
 /// The <see cref="Type"/> to filter selections.
 /// </param>
 /// <param name="typeSelectorIncludes">
 /// One of the <see cref="TypeSelectorIncludes"/> values.
 /// </param>
 public BaseTypeAttribute(Type baseType, TypeSelectorIncludes typeSelectorIncludes)
     : this(baseType, typeSelectorIncludes, null)
 {
 }
예제 #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="currentType"></param>
 /// <param name="baseType"></param>
 /// <param name="flags"></param>
 public TypeSelectorUI(Type currentType, Type baseType, TypeSelectorIncludes flags) : this(currentType, baseType, flags, null)
 {
 }
예제 #23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="currentType"></param>
 /// <param name="baseType"></param>
 /// <param name="flags"></param>
 public TypeSelectorUI(Type currentType, Type baseType, TypeSelectorIncludes flags) : this(currentType, baseType, flags, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTypeAttribute"/> class with the specified <see cref="Type"/> object and <see cref="TypeSelectorIncludes"/>.
 /// </summary>
 /// <param name="baseType">
 /// The <see cref="Type"/> to filter selections.
 /// </param>
 /// <param name="typeSelectorIncludes">
 /// One of the <see cref="TypeSelectorIncludes"/> values.
 /// </param>
 public BaseTypeAttribute(Type baseType, TypeSelectorIncludes typeSelectorIncludes)
     : this(baseType, typeSelectorIncludes, null)
 {
 }
        /// <summary>
        /// Retrieves and returns the selected type from the user.
        /// </summary>
        /// <param name="selectedType">The type to select in the type selection dialog.</param>
        /// <param name="baseType">The base type (class or interface) from which the constrained type should derive.</param>
        /// <param name="selectorIncludes">Indicates the types that can be browsed.</param>
        /// <param name="configurationType">The base type from which a type specified by the 
        /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementTypeAttribute"/>
        /// bound to the constrained type should derive, or <see langword="null"/> if no such constraint is necessary.
        /// </param>
        /// <returns>
        /// The selected <see cref="Type"/> or <see langword="null"/> if not type is selected.
        /// </returns>
        protected virtual Type GetSelectedType(Type selectedType, Type baseType, TypeSelectorIncludes selectorIncludes, Type configurationType)
        {
            var viewModel = new TypeBrowserViewModel(new TypeBuildNodeConstraint(baseType, configurationType, selectorIncludes), this);
            var selector = new TypeBrowser(viewModel, this.discoveryService);

            Nullable<bool> result = false;
            if (this.UIService != null)
            {
                result = UIService.ShowDialog(selector);
            }
            else
            {
                result = selector.ShowDialog();
            }

            if (result.HasValue && result.Value)
            {
                return selector.SelectedType;
            }
            return null;
        }
예제 #26
0
 private bool IsSet(TypeSelectorIncludes compareFlag)
 {
     return ((this.flags & compareFlag) == compareFlag);
 }
예제 #27
0
 public TypeSelector(Type currentType, Type baseType, TypeSelectorIncludes flags, TreeView treeView)
     :this(currentType, baseType, flags, null, treeView)
 {
 }
 private bool IsSet(TypeSelectorIncludes compareFlag)
 {
     return((this.TypeSelectorIncludes & compareFlag) == compareFlag);
 }