Пример #1
0
        public static List <PropertyInformation> GetProperties(object obj, Func <object, PropertyDescriptor, bool> filter)
        {
            var properties = new List <PropertyInformation>();

            if (obj is null)
            {
                return(properties);
            }

            // get the properties
            var propertyDescriptors = GetAllProperties(obj, getAllPropertiesAttributeFilter);

            // filter the properties
            foreach (var property in propertyDescriptors)
            {
                if (filter(obj, property))
                {
                    var prop = new PropertyInformation(obj, property, property.Name, property.DisplayName);
                    properties.Add(prop);
                }
            }

            // sort the properties before adding potential collection items
            properties.Sort();

            //delve path. also, issue 4919
            var extendedProps = GetExtendedProperties(obj);

            if (extendedProps != null)
            {
                properties.InsertRange(0, extendedProps);
            }

            // if the object is a collection, add the items in the collection as properties
            if (obj is ICollection collection)
            {
                var index = 0;
                foreach (var item in collection)
                {
                    var info = new PropertyInformation(item, collection, "this[" + index + "]", item);

                    index++;
                    properties.Add(info);
                }
            }

            return(properties);
        }
Пример #2
0
        /// <summary>
        /// 4919 + Delve
        /// </summary>
        /// <returns></returns>
        private static IList <PropertyInformation> GetExtendedProperties(object obj)
        {
            if (obj is null)
            {
                return(null);
            }

            if (ResourceKeyCache.Contains(obj))
            {
                var key  = ResourceKeyCache.GetKey(obj);
                var prop = new PropertyInformation(key, null, "x:Key", key, isCopyable: true);
                return(new List <PropertyInformation>
                {
                    prop
                });
            }

            if (obj is string ||
                obj.GetType().IsValueType)
            {
                return(new List <PropertyInformation> {
                    new PropertyInformation(obj, null, "ToString", obj, isCopyable: true)
                });
            }

            if (obj is AutomationPeer automationPeer)
            {
                var automationProperties = new List <PropertyInformation>
                {
                    new PropertyInformation(obj, null, "ClassName", automationPeer.GetClassName(), isCopyable: true),
                    new PropertyInformation(obj, null, "Name", automationPeer.GetName(), isCopyable: true),
                    new PropertyInformation(obj, null, "AcceleratorKey", automationPeer.GetAcceleratorKey(), isCopyable: true),
                    new PropertyInformation(obj, null, "AccessKey", automationPeer.GetAccessKey(), isCopyable: true),
                    new PropertyInformation(obj, null, "AutomationControlType", automationPeer.GetAutomationControlType(), isCopyable: true),
                    new PropertyInformation(obj, null, "AutomationId", automationPeer.GetAutomationId(), isCopyable: true),
                    new PropertyInformation(obj, null, "BoundingRectangle", automationPeer.GetBoundingRectangle(), isCopyable: true),
                    new PropertyInformation(obj, null, "ClickablePoint", automationPeer.GetClickablePoint(), isCopyable: true),
                    new PropertyInformation(obj, null, "HelpText", automationPeer.GetHelpText(), isCopyable: true),
                    new PropertyInformation(obj, null, "ItemStatus", automationPeer.GetItemStatus(), isCopyable: true),
                    new PropertyInformation(obj, null, "ItemType", automationPeer.GetItemType(), isCopyable: true),
                    new PropertyInformation(obj, null, "LabeledBy", automationPeer.GetLabeledBy(), isCopyable: true),
                        #if !NET40
                    new PropertyInformation(obj, null, "LiveSetting", automationPeer.GetLiveSetting(), isCopyable: true),
                        #endif
                    new PropertyInformation(obj, null, "LocalizedControlType", automationPeer.GetLocalizedControlType(), isCopyable: true),
                    new PropertyInformation(obj, null, "Orientation", automationPeer.GetOrientation(), isCopyable: true),
                };

                var supportedPatterns = new List <string>();

                foreach (PatternInterface patternInterface in Enum.GetValues(typeof(PatternInterface)))
                {
                    if (automationPeer.GetPattern(patternInterface) is not null)
                    {
                        supportedPatterns.Add(patternInterface.ToString());
                    }
                }

                automationProperties.Add(new PropertyInformation(obj, null, "SupportedPatterns", string.Join(", ", supportedPatterns), isCopyable: true));

                return(automationProperties);
            }

            return(null);
        }