Ejemplo n.º 1
0
        // If the type of the value to convert is string, parses the string
        // and returns the integer to set the value of the property to.
        // This example first extends the integer array that supplies the
        // standard values collection if the user-entered value is not
        // already in the array.
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            Type sourceType = typeof(object);

            if (value != null && value is ICollection)
            {
                ArrayList nonDuplicateList = new ArrayList();
                foreach (object element in (ICollection)value)
                {
                    sourceType = element.GetType();
                    break;
                }

                foreach (object element in (ICollection)value)
                {
                    if (IsExists(nonDuplicateList, element))
                    {
                        continue;
                    }
                    nonDuplicateList.Add(element);
                }
                return(ChoArray.ConvertTo(nonDuplicateList, sourceType));
            }

            return(value);
        }
Ejemplo n.º 2
0
        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
        {
            ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);

            ChoTypeProviderAttribute typeProviderAttribute = ChoType.GetAttribute <ChoTypeProviderAttribute>(GetType());

            if (typeProviderAttribute != null)
            {
                if (ChoGuard.IsArgumentNotNullOrEmpty(typeProviderAttribute.AdditionalConstructorParameters))
                {
                    return(ChoType.CreateInstance(typeProviderAttribute.Type,
                                                  ChoArray.Combine <object>(new object[] { this, defaultDescriptor, objectType, instance }, typeProviderAttribute.AdditionalConstructorParameters))
                           as ICustomTypeDescriptor);
                }
                else
                {
                    return(ChoType.CreateInstance(typeProviderAttribute.Type,
                                                  new object[] { this, defaultDescriptor, objectType, instance }) as ICustomTypeDescriptor);
                }

                //return instance == null ? defaultDescriptor : new FieldsToPropertiesTypeDescriptor(this, defaultDescriptor, objectType);
            }
            return(defaultDescriptor);
        }