Пример #1
0
 /// <summary>
 /// Adds all the extra text providers for the <see cref="AdvancedPropertyDescriptor"/>s.
 /// </summary>
 static void AddExtraTextProviders()
 {
     AdvancedPropertyDescriptor.SetExtraTextProvider <GrhIndex>(ExtraTextProvider_GrhIndex);
     AdvancedPropertyDescriptor.SetExtraTextProvider <AIID>(ExtraTextProvider_AIID);
     AdvancedPropertyDescriptor.SetExtraTextProvider <IAI>(ExtraTextProvider_IAI);
     AdvancedPropertyDescriptor.SetExtraTextProvider <AllianceID>(ExtraTextProvider_AllianceID);
     AdvancedPropertyDescriptor.SetExtraTextProvider <Alliance>(ExtraTextProvider_Alliance);
     AdvancedPropertyDescriptor.SetExtraTextProvider <BodyID>(ExtraTextProvider_BodyID);
     AdvancedPropertyDescriptor.SetExtraTextProvider <NPCChatDialogID>(ExtraTextProvider_NPCChatDialogID);
     AdvancedPropertyDescriptor.SetExtraTextProvider <ShopID>(ExtraTextProvider_ShopID);
     AdvancedPropertyDescriptor.SetExtraTextProvider <ItemTemplateID>(ExtraTextProvider_ItemTemplateID);
     AdvancedPropertyDescriptor.SetExtraTextProvider <CharacterTemplateID>(ExtraTextProvider_CharacterTemplateID);
     AdvancedPropertyDescriptor.SetExtraTextProvider <CharacterTemplateEquippedItem>(ExtraTextProvider_CharacterTemplateEquippedItem);
     AdvancedPropertyDescriptor.SetExtraTextProvider <CharacterTemplateInventoryItem>(ExtraTextProvider_CharacterTemplateInventoryItem);
 }
Пример #2
0
        /// <summary>
        /// Returns a collection of properties for the type of array specified by the value parameter, using the specified
        /// context and attributes.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides
        /// a format context.</param>
        /// <param name="value">An <see cref="T:System.Object"/> that specifies the type of array for which to
        /// get properties.</param>
        /// <param name="attributes">An array of type <see cref="T:System.Attribute"/> that is used as a filter.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> with the properties that are exposed
        /// for this data type, or null if there are no properties.
        /// </returns>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value,
                                                                   Attribute[] attributes)
        {
            var ret = new List<AdvancedPropertyDescriptor>();
            var valueType = value.GetType();

            // Get the properties to force as read-only for this type
            List<string> fro;
            lock (_forcedReadOnlySync)
            {
                _forcedReadOnly.TryGetValue(valueType, out fro);
            }

            // Get the properties to force to use a specific type converter
            List<KeyValuePair<string, TypeConverter>> ftc;
            lock (_forcedTypeConverterSync)
            {
                _forcedTypeConverter.TryGetValue(valueType, out ftc);
            }

            // Get the properties to force to use a specific editor
            List<KeyValuePair<string, UITypeEditor>> fe;
            lock (_forcedEditorSync)
            {
                _forcedEditor.TryGetValue(valueType, out fe);
            }

            // Loop through all the properties to use our custom AdvancedPropertyDescriptor instead
            foreach (var p in TypeDescriptor.GetProperties(value, attributes).OfType<PropertyDescriptor>())
            {
                var pName = p.Name;
                var propertyDescriptor = new AdvancedPropertyDescriptor(p, value);

                // Apply the forced values
                if (fro != null && fro.Contains(propertyDescriptor.Name))
                    propertyDescriptor.ForceReadOnly = true;

                if (ftc != null)
                    propertyDescriptor.ForceTypeConverter = ftc.FirstOrDefault(x => _propSC.Equals(pName, x.Key)).Value;

                if (fe != null)
                    propertyDescriptor.ForceEditor = fe.FirstOrDefault(x => _propSC.Equals(pName, x.Key)).Value;

                // Add to the return list
                ret.Add(propertyDescriptor);
            }

            return new PropertyDescriptorCollection(ret.ToArray());
        }