コード例 #1
0
        /// <summary>
        /// Edits the value of the specified object.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain
        /// additional context information.</param>
        /// <param name="provider">An <see cref="IServiceProvider"/> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var baseTypeAttribute = GetBaseTypeAttribute(context);
            var constraint =
                    new TypeBuildNodeConstraint(
                        baseTypeAttribute.BaseType,
                        baseTypeAttribute.ConfigurationType,
                        baseTypeAttribute.TypeSelectorIncludes);

            var model = new TypeBrowserViewModel(constraint, provider);
            var window =
                new TypeBrowser(model, (IAssemblyDiscoveryService)provider.GetService(typeof(IAssemblyDiscoveryService)));

            var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf));
            if (service != null)
            {
                service.ShowDialog(window);
            }
            else
            {
                window.ShowDialog();
            }

            if (window.DialogResult.HasValue && window.DialogResult.Value)
            {
                return window.SelectedType != null ? window.SelectedType.AssemblyQualifiedName : null;
            }

            return value;
        }
コード例 #2
0
        /// <summary>
        /// Edits the value of the specified object.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain
        /// additional context information.</param>
        /// <param name="provider">An <see cref="IServiceProvider"/> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var baseTypeAttribute = GetBaseTypeAttribute(context);
            var constraint        =
                new TypeBuildNodeConstraint(
                    baseTypeAttribute.BaseType,
                    baseTypeAttribute.ConfigurationType,
                    baseTypeAttribute.TypeSelectorIncludes);

            var model  = new TypeBrowserViewModel(constraint, provider);
            var window =
                new TypeBrowser(model, (IAssemblyDiscoveryService)provider.GetService(typeof(IAssemblyDiscoveryService)));

            var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf));

            if (service != null)
            {
                service.ShowDialog(window);
            }
            else
            {
                window.ShowDialog();
            }

            if (window.DialogResult.HasValue && window.DialogResult.Value)
            {
                return(window.SelectedType != null ? window.SelectedType.AssemblyQualifiedName : null);
            }

            return(value);
        }
コード例 #3
0
        public void AcceptsAbstractAndNonPublicTypesIfSpecified()
        {
            var constraint = new TypeBuildNodeConstraint(typeof(object), null, TypeSelectorIncludes.AbstractTypes | TypeSelectorIncludes.NonpublicTypes);

            Assert.IsFalse(constraint.Matches(typeof(object)));
            Assert.IsTrue(constraint.Matches(typeof(BaseType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedType.NestedType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedType.NestedInternalType)));
            Assert.IsTrue(constraint.Matches(typeof(AbstractType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedFromAbstractType)));
            Assert.IsFalse(constraint.Matches(typeof(IBase)));
            Assert.IsFalse(constraint.Matches(typeof(IDerived)));
            Assert.IsTrue(constraint.Matches(typeof(InternalType)));
            Assert.IsTrue(constraint.Matches(typeof(InternalAbstractType)));
        }
コード例 #4
0
        public void AcceptsPublicNonAbstractNonInterfaceTypesByDefault()
        {
            var constraint = new TypeBuildNodeConstraint(typeof(object), null, TypeSelectorIncludes.None);

            Assert.IsFalse(constraint.Matches(typeof(object)));
            Assert.IsTrue(constraint.Matches(typeof(BaseType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedType.NestedType)));
            Assert.IsFalse(constraint.Matches(typeof(DerivedType.NestedInternalType)));
            Assert.IsFalse(constraint.Matches(typeof(AbstractType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedFromAbstractType)));
            Assert.IsFalse(constraint.Matches(typeof(IBase)));
            Assert.IsFalse(constraint.Matches(typeof(IDerived)));
            Assert.IsFalse(constraint.Matches(typeof(InternalType)));
            Assert.IsFalse(constraint.Matches(typeof(InternalAbstractType)));
        }
コード例 #5
0
 public void ConfigurationElementTypeIsReferredToInDisplayString()
 {
     var constraint = new TypeBuildNodeConstraint(typeof(Guid), typeof(double), TypeSelectorIncludes.None);
     Assert.IsTrue(constraint.GetDisplayString().IndexOf("double", StringComparison.OrdinalIgnoreCase) > -1);
 }
コード例 #6
0
 public void BaseTypeIsReferredToInDisplayString()
 {
     var constraint = new TypeBuildNodeConstraint(typeof(Guid), null, TypeSelectorIncludes.None);
     Assert.IsTrue(constraint.GetDisplayString().IndexOf("Guid", StringComparison.OrdinalIgnoreCase) > -1);
 }
コード例 #7
0
        public void AcceptsOnlyTypesWithTheConfigurationElementTypeIfSpecified()
        {
            var constraint =
                new TypeBuildNodeConstraint(
                    typeof(object),
                    typeof(int),
                    TypeSelectorIncludes.Interfaces | TypeSelectorIncludes.AbstractTypes | TypeSelectorIncludes.BaseType | TypeSelectorIncludes.NonpublicTypes);

            Assert.IsFalse(constraint.Matches(typeof(object)));
            Assert.IsFalse(constraint.Matches(typeof(BaseType)));
            Assert.IsFalse(constraint.Matches(typeof(DerivedType)));
            Assert.IsFalse(constraint.Matches(typeof(DerivedType.NestedType)));
            Assert.IsFalse(constraint.Matches(typeof(DerivedType.NestedInternalType)));
            Assert.IsFalse(constraint.Matches(typeof(AbstractType)));
            Assert.IsTrue(constraint.Matches(typeof(DerivedFromAbstractType)));
            Assert.IsFalse(constraint.Matches(typeof(IBase)));
            Assert.IsFalse(constraint.Matches(typeof(IDerived)));
            Assert.IsFalse(constraint.Matches(typeof(InternalType)));
            Assert.IsFalse(constraint.Matches(typeof(InternalAbstractType)));
        }
コード例 #8
0
            public void DoTestAcceptsTypesFromDifferentLoadContext()
            {
                var newAssembly = Assembly.LoadFrom(AssemblyFileName);

                var constraint =
                    new TypeBuildNodeConstraint(
                        typeof(IBase),
                        null,
                        TypeSelectorIncludes.Interfaces | TypeSelectorIncludes.AbstractTypes | TypeSelectorIncludes.BaseType | TypeSelectorIncludes.NonpublicTypes);

                Assert.IsTrue(constraint.Matches(newAssembly.GetType(typeof(BaseType).FullName, true)));
                Assert.IsTrue(constraint.Matches(newAssembly.GetType(typeof(DerivedType).FullName, true)));
                Assert.IsFalse(constraint.Matches(newAssembly.GetType(typeof(DerivedType.NestedType).FullName, true)));
                Assert.IsFalse(constraint.Matches(newAssembly.GetType(typeof(DerivedType.NestedInternalType).FullName, true)));
                Assert.IsFalse(constraint.Matches(newAssembly.GetType(typeof(AbstractType).FullName, true)));
                Assert.IsFalse(constraint.Matches(newAssembly.GetType(typeof(DerivedFromAbstractType).FullName, true)));
                Assert.IsTrue(constraint.Matches(newAssembly.GetType(typeof(IBase).FullName, true)));
                Assert.IsTrue(constraint.Matches(newAssembly.GetType(typeof(IDerived).FullName, true)));
                Assert.IsFalse(constraint.Matches(newAssembly.GetType(typeof(InternalType).FullName, true)));
                Assert.IsFalse(constraint.Matches(newAssembly.GetType(typeof(InternalAbstractType).FullName, true)));
            }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeBrowserViewModel"/> class with a 
 /// <see cref="TypeBuildNodeConstraint"/> and a service provider.
 /// </summary>
 /// <param name="constraint">The constraint to use when filtering types.</param>
 /// <param name="serviceProvider">The service provider.</param>
 public TypeBrowserViewModel(TypeBuildNodeConstraint constraint, IServiceProvider serviceProvider)
     : this(constraint.Matches, serviceProvider)
 {
     typeConstraintDisplay = constraint.GetDisplayString();
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeBrowserViewModel"/> class with a
 /// <see cref="TypeBuildNodeConstraint"/> and a service provider.
 /// </summary>
 /// <param name="constraint">The constraint to use when filtering types.</param>
 /// <param name="serviceProvider">The service provider.</param>
 public TypeBrowserViewModel(TypeBuildNodeConstraint constraint, IServiceProvider serviceProvider)
     : this(constraint.Matches, serviceProvider)
 {
     typeConstraintDisplay = constraint.GetDisplayString();
 }