/// <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; }
/// <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); }
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))); }
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))); }
public void ConfigurationElementTypeIsReferredToInDisplayString() { var constraint = new TypeBuildNodeConstraint(typeof(Guid), typeof(double), TypeSelectorIncludes.None); Assert.IsTrue(constraint.GetDisplayString().IndexOf("double", StringComparison.OrdinalIgnoreCase) > -1); }
public void BaseTypeIsReferredToInDisplayString() { var constraint = new TypeBuildNodeConstraint(typeof(Guid), null, TypeSelectorIncludes.None); Assert.IsTrue(constraint.GetDisplayString().IndexOf("Guid", StringComparison.OrdinalIgnoreCase) > -1); }
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))); }
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))); }
/// <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(); }