示例#1
0
        private static bool InspectField(Inspector inspector, string path, ref object data, FieldInfo fieldInfo,
                                         string prefix)
        {
            object    value      = fieldInfo.GetValue(data);
            FieldInfo info       = fieldInfo;
            bool      inwritable = info.IsInitOnly || info.IsLiteral;
            Type      valueType  = value != null?value.GetType() : info.FieldType;

            bool   changed      = false;
            object changedvalue = null;
            var    mark         = TypeTools.GetAttribute <IMark>(info);

            if (inwritable)
            {
                inspector.Inspect(prefix + fieldInfo.Name, path + "." + fieldInfo.Name, value, valueType, mark);
            }
            else
            {
                inspector.Inspect(prefix + fieldInfo.Name, path + "." + fieldInfo.Name, value, valueType, mark, v =>
                {
                    changed      = true;
                    changedvalue = v;
                });
            }

            if (changed)
            {
                info.SetValue(data, changedvalue);
            }
            return(changed);
        }
示例#2
0
        public override object[] Keys(Inspector.Options options, object collection)
        {
            object[] keys  = new object[((IDictionary)collection).Count];
            int      index = 0;

            foreach (var key in ((IDictionary)collection).Keys)
            {
                keys[index++] = key;
            }
            TypeTools.TrySort(keys);
            return(keys);
        }
        public override bool InspectSelf(Inspector inspector, string name, ref object data, Type type)
        {
            var e = data as Enum;

            if (e == null)
            {
                return(false);
            }
            if (TypeTools.GetAttribute <FlagsAttribute>(type) != null)
            {
                return(ApplyValueIfNotEqual(ref data, GUITools.EnumMaskField(name, e)));
            }
            else
            {
                return(ApplyValueIfNotEqual(ref data, GUITools.EnumPopup(name, e)));
            }
        }
        public override bool InspectChildren(Inspector inspector, string path, ref object data, Type type)
        {
            var c = data as IEnumerable;

            if (c == null)
            {
                return(false);
            }

            var hashsetValueType = TypeTools.FindGenericParamType(type, typeof(HashSet <>), 0);

            int  i       = 0;
            bool changed = false;

            foreach (var value in c)
            {
                Type valueType = value != null?value.GetType() : hashsetValueType;

                changed |= inspector.Inspect(i.ToString(), path + "." + i, value, valueType);
                ++i;
            }
            return(changed);
        }
        public override object Resize(object collection, int size)
        {
            IList list = (IList)collection;

            var elemType = ValueType(collection);

            while (list.Count > size)
            {
                list.RemoveAt(list.Count - 1);
            }
            while (list.Count < size)
            {
                if (elemType.IsClass)
                {
                    list.Add(null);
                }
                else
                {
                    list.Add(TypeTools.CreateInstance(elemType));
                }
            }
            return(list);
        }
 public override object Resize(object collection, int size)
 {
     return(TypeTools.ResizeArray(collection as Array, size));
 }
示例#7
0
 public override Type ValueType(object collection)
 {
     return(TypeTools.FindGenericParamType(collection.GetType(), typeof(Dictionary <,>), 1));
 }
 public override Type ValueType(object collection)
 {
     return(TypeTools.FindGenericParamType(collection.GetType(), typeof(List <>), 0));
 }