private static Type GetExtensionType(INuPatternProjectTypeProvider provider, IEnumerable <Lazy <TComponents, IComponentMetadata> > components, string extensionName) { if (string.IsNullOrEmpty(extensionName)) { return(null); } // Locate type from exports first var extensionType = components.FromComponentCatalog() .Where(binding => binding.Metadata.Id == extensionName) .Select(binding => binding.Metadata.ExportingType) .FirstOrDefault(); if (extensionType == null) { if (provider == null) { return(null); } // Locate type in solution assemblies extensionType = (from type in provider.GetTypes <TComponents>() let meta = type.AsProjectComponent() where meta != null && meta.Id == extensionName select type) .FirstOrDefault(); } return(extensionType); }
/// <summary> /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context. /// </summary> /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param> /// <returns> /// A <see cref="TypeConverter.StandardValuesCollection"/> that holds a standard set of valid values, or null if the data type does not support a standard set of values. /// </returns> public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (ProjectTypeProvider == null || ValueProviders == null) { ProjectTypeProvider = NuPatternCompositionService.Instance.GetExportedValue <INuPatternProjectTypeProvider>(); ValueProviders = NuPatternCompositionService.Instance .GetExports <IValueProvider, IComponentMetadata>() .FromComponentCatalog() .Where(value => value.Metadata.ExportingType.IsBrowsable()); } return(this.StandardValues); }
public static IEnumerable <PropertyDescriptor> GetComponentProperties(INuPatternProjectTypeProvider provider, IEnumerable <Lazy <TComponents, IComponentMetadata> > components, string extensionName) { Guard.NotNull(() => provider, provider); Guard.NotNull(() => components, components); var properties = new List <PropertyDescriptor>(); if (!String.IsNullOrEmpty(extensionName)) { // Find the extension type. var extensionType = GetExtensionType(provider, components, extensionName); if (extensionType != null) { // Project descriptors from component onto the current instance. var descriptors = TypeDescriptor.GetProperties(extensionType) .Cast <PropertyDescriptor>() .Where(d => d.IsBindableDesignProperty()); foreach (var descriptor in descriptors) { // Determine if a collection design property if (descriptor.IsAutoDesignCollectionProperty()) { properties.Add(new DesignCollectionPropertyDescriptor <TInstance>(descriptor)); } else { // Determine if a [DesignOnly(true)] property if (descriptor.IsDesignOnlyProperty()) { properties.Add(new DesignOnlyPropertyDescriptor(descriptor)); } else { // Regular design property properties.Add(new DesignPropertyDescriptor( descriptor.Name, descriptor.PropertyType, typeof(TInstance), descriptor.Attributes.Cast <Attribute>().ToArray())); } } } } } return(properties); }
/// <summary> /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context. /// </summary> /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param> /// <returns> /// A <see cref="TypeConverter.StandardValuesCollection"/> that holds a standard set of valid values, or null if the data type does not support a standard set of values. /// </returns> public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (ProjectTypeProvider == null || ValueProviders == null) { ProjectTypeProvider = NuPatternCompositionService.Instance.GetExportedValue<INuPatternProjectTypeProvider>(); ValueProviders = NuPatternCompositionService.Instance .GetExports<IValueProvider, IComponentMetadata>() .FromComponentCatalog() .Where(value => value.Metadata.ExportingType.IsBrowsable()); } return this.StandardValues; }