Esempio n. 1
0
        void Analyze(object val, string name, Type type,
                     Action <object> setter, GroupViewProperty property, HashSet <int> hashed)
        {
            try {
                if (type.IsPrimitive || Type.GetTypeCode(type) == TypeCode.String)
                {
                    var             converter = GetConverter(type);
                    Action <string> change    = x => setter(converter(x));
                    property.AddPrimitive(name, val, change);
                    return;
                }
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    var valuetext = val.IsNull() ? "null" : ((System.Collections.ICollection)val).Count.ToString();
                    var value     = $"{type.GenericTypeArguments.First().Name}[{valuetext}]";
                    property.AddPrimitive(name, value, x => { });
                    return;
                }
                var group = new GroupViewProperty();
                group.Title = name;

                if (type.IsValueType && !type.IsEnum)
                {
                    group.AnalyzeValueType(val, group, type);
                }
                else
                {
                    group.Analyze(val, group, type, hashed);
                }
                if (group.Value.Any())
                {
                    Value.Add(group);
                }
                else if (type.IsEnum)
                {
                    var fields = type.GetFields().ToList();
                    fields.RemoveAt(0);
                    void change(string x) => setter(Enum.Parse(type, x));

                    var values = fields.Select(x => x.Name).ToArray();
                    property.AddSequence(name, val, change, values);
                }
                else
                {
                    property.AddPrimitive(name, val, x => { });
                }
            } catch (Exception ex) {
                ex.ToString();
            }
        }
Esempio n. 2
0
        void Analyze(object com, GroupViewProperty property, PropertyInfo pr, HashSet <int> hashed)
        {
            var name = pr.Name;

            try {
                if (pr.CustomAttributes.Any(x => x.AttributeType == typeof(IgnoreDebugingAttribute)))
                {
                    return;
                }

                var val = com.IsNull() ? null : pr.GetValue(com);

                if (val.IsNotNull())
                {
                    if (hashed.Contains(val.GetHashCode()))
                    {
                        return;
                    }
                    hashed.Add(pr.GetHashCode());
                }

                var type = pr.PropertyType;
                if (type.IsPrimitive || Type.GetTypeCode(type) == TypeCode.String)
                {
                    var             converter = GetConverter(type);
                    Action <string> change    = x => pr.SetValue(com, converter(x));
                    switch (Type.GetTypeCode(type))
                    {
                    case TypeCode.Boolean:
                        property.AddSequence(name, val, change, new[] { bool.TrueString, bool.FalseString });
                        break;

                    default:
                        property.AddPrimitive(name, val, change);
                        break;
                    }
                    return;
                }
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    var valuetext = val.IsNull() ? "null" : ((System.Collections.ICollection)val).Count.ToString();
                    var value     = $"{type.GenericTypeArguments.First().Name}[{valuetext}]";
                    property.AddPrimitive(name, value, x => { });
                    return;
                }

                if (type == typeof(System.Drawing.Bitmap))
                {
                    property.AddImage((System.Drawing.Bitmap)val);
                    return;
                }

                var group = new GroupViewProperty();
                group.Title = name;

                if (type.IsValueType && !type.IsEnum)
                {
                    if (NumericsTypes.IsVector3(type))
                    {
                        group.AddVector(name, val, x => { pr.SetValue(com, x); });
                    }
                    else
                    {
                        group.AnalyzeValueType(val, group, type);
                    }
                    //switch (type.FullName) {
                    //    case "System.Numerics.Vector3":
                    //        group.AddVector(name, val, x => { pr.SetValue(com, x); });
                    //        break;
                    //    default:
                    //        group.AnalyzeValueType(val, group, type);
                    //        break;
                    //}
                }
                else if (type.IsArray)
                {
                    var list = (System.Collections.IList)val;
                    if (list.Count < 10)
                    {
                        for (var index = 0; index < list.Count; index++)
                        {
                            var i = list[index];
                            switch (i)
                            {
                            case System.IO.FileInfo fi:
                                group.AddFileInfo(new ObjUpdaterInArray(list, index), fi);
                                break;
                                //default:
                                //    group.Analyze(i, group, i.GetType(), hashed);
                                //    break;
                            }
                        }
                    }
                }
                else
                {
                    group.Analyze(val, group, type, hashed);
                }
                if (group.Value.Any())
                {
                    Value.Add(group);
                }
                else if (type.IsEnum)
                {
                    var fields = type.GetFields().ToList();
                    fields.RemoveAt(0);
                    void change(string x) => pr.SetValue(com, Enum.Parse(type, x));

                    var values = fields.Select(x => x.GetValue(com).ToString()).ToArray();
                    property.AddSequence(name, val, change, values);
                }
                else
                {
                    property.AddPrimitive(name, val, x => { });
                }
            } catch (Exception ex) {
                ex.ToString();
            }
        }