public override void SetValue(object component, object value)
        {
            string str = value as string;

            if ((str != null) && (str.Length > 0))
            {
                ITypeProvider service = (ITypeProvider)base.ServiceProvider.GetService(typeof(ITypeProvider));
                if (service == null)
                {
                    throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                }
                Type type = service.GetType(value as string);
                if (type == null)
                {
                    throw new Exception(SR.GetString("Error_TypeNotResolved", new object[] { value }));
                }
                TypeFilterProviderAttribute attribute = this.Attributes[typeof(TypeFilterProviderAttribute)] as TypeFilterProviderAttribute;
                if (attribute != null)
                {
                    ITypeFilterProvider provider2 = null;
                    Type type2 = Type.GetType(attribute.TypeFilterProviderTypeName);
                    if (type2 != null)
                    {
                        provider2 = Activator.CreateInstance(type2, new object[] { base.ServiceProvider }) as ITypeFilterProvider;
                    }
                    if (provider2 != null)
                    {
                        provider2.CanFilterType(type, true);
                    }
                }
                value = type.AssemblyQualifiedName;
            }
            base.RealPropertyDescriptor.SetValue(component, value);
        }
Ejemplo n.º 2
0
 private void DetermineFilterType(ITypeDescriptorContext context)
 {
     if (filterType == null)
     {
         // Look for the attribute in the argument type itself.
         TypeFilterProviderAttribute filterProvider = context.PropertyDescriptor.Attributes[typeof(TypeFilterProviderAttribute)] as TypeFilterProviderAttribute;
         if (filterProvider != null)
         {
             filterType = GetValidFilterType(filterProvider.TypeFilterProviderTypeName);
         }
     }
     if (filterType == null)
     {
         filterType = typeof(PublicTypeFilter);
     }
 }
Ejemplo n.º 3
0
        private void DetermineFilterType(ITypeDescriptorContext context)
        {
            ITypeResolutionService resolution = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService));

            if (!String.IsNullOrEmpty(filterTypeName) && filterType == null)
            {
                filterType = GetValidFilterType(resolution, filterTypeName);
            }
            if (filterType == null)
            {
                // Look for the attribute in the argument type itself.
                TypeFilterProviderAttribute filterProvider = (TypeFilterProviderAttribute)context.PropertyDescriptor.Attributes[typeof(TypeFilterProviderAttribute)];
                filterType = GetValidFilterType(resolution, filterProvider.TypeFilterProviderTypeName);
            }
            if (filterType == null)
            {
                filterType = typeof(PublicTypeFilter);
            }
        }
        public override void SetValue(object component, object value)
        {
            string typeName = value as String;

            if (typeName != null && typeName.Length > 0)
            {
                ITypeProvider typeProvider = (ITypeProvider)this.ServiceProvider.GetService(typeof(ITypeProvider));
                if (typeProvider == null)
                {
                    throw new Exception(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
                }

                Type type = typeProvider.GetType(value as string);
                if (type == null)
                {
                    throw new Exception(SR.GetString(SR.Error_TypeNotResolved, value));
                }

                TypeFilterProviderAttribute filterProviderAttribute = this.Attributes[typeof(TypeFilterProviderAttribute)] as TypeFilterProviderAttribute;
                if (filterProviderAttribute != null)
                {
                    ITypeFilterProvider typeFilterProvider = null;
                    Type typeFilterProviderType            = Type.GetType(filterProviderAttribute.TypeFilterProviderTypeName);
                    if (typeFilterProviderType != null)
                    {
                        typeFilterProvider = Activator.CreateInstance(typeFilterProviderType, new object[] { this.ServiceProvider }) as ITypeFilterProvider;
                    }
                    if (typeFilterProvider != null)
                    {
                        typeFilterProvider.CanFilterType(type, true);
                    }
                }
                // we always store assembly qualified name of the type
                value = type.AssemblyQualifiedName;
            }

            RealPropertyDescriptor.SetValue(component, value);
        }