Ejemplo n.º 1
0
        internal static List <(string, string)> PropertyValuesFor(Control control)
        {
            var members = new List <(string, string)>();
            var type    = control.GetType();

            foreach (var fieldInfo in type.GetAllFields())
            {
                if (!ViewVariablesUtility.TryGetViewVariablesAccess(fieldInfo, out _))
                {
                    continue;
                }

                members.Add((fieldInfo.Name, fieldInfo.GetValue(control)?.ToString() ?? "null"));
            }

            foreach (var propertyInfo in type.GetAllProperties())
            {
                if (!ViewVariablesUtility.TryGetViewVariablesAccess(propertyInfo, out _))
                {
                    continue;
                }

                members.Add((propertyInfo.Name, propertyInfo.GetValue(control)?.ToString() ?? "null"));
            }

            foreach (var(attachedProperty, value) in control.AllAttachedProperties)
            {
                members.Add(($"{attachedProperty.OwningType.Name}.{attachedProperty.Name}",
                             value?.ToString() ?? "null"));
            }

            members.Sort((a, b) => string.Compare(a.Item1, b.Item1, StringComparison.Ordinal));
            return(members);
        }
Ejemplo n.º 2
0
        protected internal static IEnumerable <IGrouping <Type, Control> > LocalPropertyList(object obj, IViewVariablesManagerInternal vvm,
                                                                                             IRobustSerializer robustSerializer)
        {
            var styleOther = false;
            var type       = obj.GetType();

            var members = new List <(MemberInfo, VVAccess, object?value, Action <object?, bool> onValueChanged, Type)>();

            foreach (var fieldInfo in type.GetAllFields())
            {
                if (!ViewVariablesUtility.TryGetViewVariablesAccess(fieldInfo, out var access))
                {
                    continue;
                }

                members.Add((fieldInfo, (VVAccess)access, fieldInfo.GetValue(obj), (v, _) => fieldInfo.SetValue(obj, v),
                             fieldInfo.FieldType));
            }

            foreach (var propertyInfo in type.GetAllProperties())
            {
                if (!ViewVariablesUtility.TryGetViewVariablesAccess(propertyInfo, out var access))
                {
                    continue;
                }

                if (!propertyInfo.IsBasePropertyDefinition())
                {
                    continue;
                }

                members.Add((propertyInfo, (VVAccess)access, propertyInfo.GetValue(obj),
                             (v, _) => propertyInfo.GetSetMethod(true) !.Invoke(obj, new[] { v }), propertyInfo.PropertyType));
            }

            var groupedSorted = members
                                .OrderBy(p => p.Item1.Name)
                                .GroupBy(p => p.Item1.DeclaringType !, tuple =>
            {
                var(memberInfo, access, value, onValueChanged, memberType) = tuple;
                var data = new ViewVariablesBlobMembers.MemberData
                {
                    Editable   = access == VVAccess.ReadWrite,
                    Name       = memberInfo.Name,
                    Type       = memberType.AssemblyQualifiedName,
                    TypePretty = TypeAbbreviation.Abbreviate(memberType),
                    Value      = value
                };

                var propertyEdit = new ViewVariablesPropertyControl(vvm, robustSerializer);
                propertyEdit.SetStyle(styleOther = !styleOther);
                var editor             = propertyEdit.SetProperty(data);
                editor.OnValueChanged += onValueChanged;
                return(propertyEdit);
            })
                                .OrderByDescending(p => p.Key, TypeHelpers.TypeInheritanceComparer);

            return(groupedSorted);
        }