public RVControlBase(string nameLabel, object data, int depth, RVVisibility rvVisibility) { this.NameLabel = nameLabel; this.data = data; this.depth = depth; this.rvVisibility = rvVisibility; }
RVControlBase CreateControl(object ob, string fieldName, RVVisibility rvVisibility) { RVControlBase b = null; if (IsNull(ob) == true) { b = new RVText(fieldName, null, depth + 1, rvVisibility); } else { Type t = ob.GetType(); if (RVHelper.IsCanToStringDirently(t) == true) { b = new RVText(fieldName, ob, depth + 1, rvVisibility); } else { RVVisibility rvv = rvVisibility.GetCopy(); if (RVHelper.IsCollection(t) == false) { rvv.RVType = RVVisibility.NameType.Class; } // Debug.Log("--------------" + this.NameLabel); b = new RVCollection(this.parentNameLabel + this.NameLabel, GetSpecialNameLabel(ob, fieldName), ob, depth + 1, rvv); } } return(b); }
//所有集合判断,数组,字典,list等等 List <RVControlBase> AnalyzeCollection(object ob, Type type) { List <RVControlBase> result = new List <RVControlBase>(); if (typeof(IDictionary).IsAssignableFrom(type) == true)//是个字典 { IDictionary dic = ob as IDictionary; foreach (DictionaryEntry item in dic) { string _key = "null"; Type _type = null; if (IsNull(item.Key) == false) { _key = item.Key.ToString(); } if (IsNull(item.Value) == false) { _type = item.Value.GetType(); } RVVisibility rvv = new RVVisibility(RVVisibility.NameType.CollectionItem, _type); result.Add(CreateControl(item.Value, "[" + _key + "]", rvv)); } } else if (typeof(ICollection).IsAssignableFrom(type) == true) //是个集合 { foreach (var _v in (ICollection)ob) { string str = "item"; Type _type = null; if (IsNull(_v) == false) { _type = _v.GetType(); if (RVHelper.IsString(_type) == true || RVHelper.IsCanToStringDirently(_type) == true) { str = "item"; } else if (RVHelper.IsNormalType(_type) == false) { str = _v.ToString(); } } RVVisibility rvv = new RVVisibility(RVVisibility.NameType.CollectionItem, _type); result.Add(CreateControl(_v, str, rvv)); } } return(result); }
Dictionary <RVCollection, RVCStatus> CreateRVCollections() { Dictionary <RVCollection, RVCStatus> result = new Dictionary <RVCollection, RVCStatus>(); if (nowSelectItem != null) { Component[] c = RVHelper.GetComponent(nowSelectItem); if (c != null) { foreach (var item in c) { if (item == null) { continue; } RVVisibility rvv = new RVVisibility(); rvv.RVType = RVVisibility.NameType.Class; string rvcName = item.GetType().ToString().Replace("UnityEngine.", ""); if (IsContainsKey(result, rvcName) == true) { rvcName += "#" + item.GetInstanceID(); } RVCollection rvc = new RVCollection(nowSelectItem.name, rvcName, item, 0, rvv); RVCStatus rvCStatus = new RVCStatus(); if (rvCStatusForAllObject.ContainsKey(nowSelectItem.GetInstanceID()) == true) { rvCStatus = rvCStatusForAllObject[nowSelectItem.GetInstanceID()]; } else { rvCStatusForAllObject.Add(nowSelectItem.GetInstanceID(), rvCStatus); } result.Add(rvc, rvCStatus); } } } return(result); }
public RVText(string nameLabel, object data, int depth, RVVisibility rvVisibility) : base(nameLabel, data, depth, rvVisibility) { Init(); }
List <RVControlBase> AnalyzeClass(object data, Type thisType) { List <RVControlBase> result = new List <RVControlBase>(); while (thisType.IsSubclassOf(typeof(object))) { FieldInfo[] fields = thisType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); foreach (FieldInfo field in fields) { if (IsForbidThis(data, field.Name) == true) { continue; } object value = field.GetValue(data); RVVisibility rvv = new RVVisibility(); rvv.RVType = RVVisibility.NameType.Field; rvv.ValueType = field.FieldType; rvv.IsPrivate = field.IsPrivate; rvv.IsPublic = field.IsPublic; RVControlBase cb = CreateControl(value, field.Name, rvv); if (result.Contains(cb) == false) { result.Add(cb); } } PropertyInfo[] properties = thisType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); foreach (PropertyInfo property in properties) { object value = null; try { if (IsForbidThis(data, property.Name) == true) { continue; } value = property.GetValue(data, null); } catch { value = null; } RVVisibility rvv = new RVVisibility(); rvv.RVType = RVVisibility.NameType.Property; rvv.PropertyCanRead = property.CanRead; rvv.PropertyCanWrite = property.CanWrite; rvv.ValueType = property.PropertyType; RVControlBase cb = CreateControl(value, property.Name, rvv); if (result.Contains(cb) == false) { result.Add(cb); } } thisType = thisType.BaseType; } // //result.Sort((a, b) => //{ // return string.Compare(a.NameLabel, b.NameLabel, false, System.Globalization.CultureInfo.InvariantCulture); //}); return(result); }
public RVCollection(string parentNameLabel, string nameLabel, object data, int depth, RVVisibility rvVisibility) : base(nameLabel, data, depth, rvVisibility) { this.parentNameLabel = parentNameLabel; }