/// <summary> /// Inherit default values from parent type, for some settings like color /// </summary> /// <param name="sME">The s me.</param> protected void inheritMissingSettings(settingsMemberInfoEntry sME) { if (TypeInfo == sME) { return; } if (sME.color.isNullOrEmpty()) { sME.color = color; } }
/// <summary> /// Processes the type. /// </summary> /// <param name="type">The type.</param> /// <param name="includeCollectionItems">if set to <c>true</c> [include collection items].</param> /// <param name="target">The target.</param> protected void processType(Type type, Boolean includeCollectionItems, Object target = null, Int32 call = 0) { targetType = type; TypeInfo = new settingsMemberInfoEntry(type); var pTypes = type.GetBaseTypeList(false, true, null, call++); pTypes.Add(type); List <PropertyInfo> props = new List <PropertyInfo>(); foreach (var t in pTypes) { var pr = t.GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance); props.AddRange(pr); } List <PropertyInfo> propList = new List <PropertyInfo>(); foreach (PropertyInfo pro in props) { if (pro.CanWrite) { if (pro.PropertyType.IsEnum) { propList.Add(pro); } else if (pro.PropertyType.IsPrimitive) { propList.Add(pro); } else if (pro.PropertyType == typeof(String)) { propList.Add(pro); } else { if (pro.DeclaringType == targetType) { if (pro.Name != "Item") { propList.Add(pro); } else { } } } } } // propList.Sort(SortProperty); foreach (PropertyInfo pro in propList) { if (!pis.ContainsKey(pro.Name)) { pis.Add(pro.Name, pro); settingsPropertyEntryWithContext spe = new settingsPropertyEntryWithContext(pro, target, pce); spes.Add(pro.Name, spe); } } if (includeCollectionItems) { if (target is IList) { IList l = target as IList; foreach (var i in l) { settingsPropertyEntryWithContext spe = new settingsPropertyEntryWithContext(i, l, pce); spes.Add(spe.displayName, spe); } } } //// SORTING List <settingsPropertyEntryWithContext> tempList = new List <settingsPropertyEntryWithContext>(); // SORTING BY CATEGORY if (CategoryByPriority.Count > 0) { //aceDictionarySet<String, settingsPropertyEntry> pi_set = new aceDictionarySet<string, settingsPropertyEntry>(); Int32 pri = CategoryByPriority.Count; foreach (String cat in CategoryByPriority) { IEnumerable <settingsPropertyEntryWithContext> propInCat = spes.Values.Where(x => x.categoryName.ToLower() == cat.ToLower()); foreach (settingsPropertyEntryWithContext pic in propInCat) { pic.priority = (CategoryPrioritySpaceSize * pri) + pic.priority; tempList.Add(pic); } pri--; } foreach (var pair in spes) { if (!tempList.Contains(pair.Value)) { if (!CategoryByPriority.Contains(pair.Value.categoryName)) { CategoryByPriority.Add(pair.Value.categoryName); } tempList.Add(pair.Value); } } } else { foreach (settingsPropertyEntryWithContext pic in spes.Values) { tempList.Add(pic); } } // DEPLOYING PRIORITY SETTINGS INTO INDEX tempList = tempList.OrderByDescending(x => x.priority).ToList(); spes.Clear(); Int32 index = 0; foreach (var pic in tempList) { pic.index = index; index++; spes.Add(pic.name, pic); } // INHERITS MISSING VALUES foreach (var pair in spes) { inheritMissingSettings(pair.Value); } }
/// <summary> /// Creates DataTable for reporting {T} <c>instance</c> purposes. /// </summary> /// <param name="targetType">Type of the target.</param> /// <param name="onlyDeclared">if set to <c>true</c> [only declared].</param> /// <param name="plist">The plist.</param> /// <param name="table">The table.</param> /// <param name="doRemoveReportedProperties">if set to <c>true</c> [do remove reported properties].</param> /// <returns></returns> public static DataTable ReportMakeDataTable(this Type targetType, Boolean onlyDeclared = true, List <PropertyInfo> plist = null, DataTable table = null, Boolean doRemoveReportedProperties = true) { if (table == null) { table = new DataTable(); settingsMemberInfoEntry sme = new settingsMemberInfoEntry(targetType); table.SetSME(sme); } if (plist == null) { plist = targetType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).ToList(); } foreach (var pi in plist.ToList()) { if (onlyDeclared && pi.DeclaringType != targetType) { continue; } Boolean removePi = true; settingsPropertyEntry spe = new settingsPropertyEntry(pi); if (pi.PropertyType.IsValueType || pi.PropertyType == typeof(String)) { if (!table.Columns.Contains(pi.Name)) { table.Columns.Add(pi.Name, pi.PropertyType).SetSPE(spe); } //output.AppendLine(pi.Name + "\t\t\t" + vl.toStringSafe()); } else if (pi.PropertyType == typeof(List <String>)) { if (!table.Columns.Contains(pi.Name)) { table.Columns.Add(pi.Name, typeof(String)).SetSPE(spe).SetDesc("Comma separated values from string list"); } //output.AppendLine(pi.Name + "\t\t\t" + stringList.toCsvInLine()); } else if (pi.PropertyType == typeof(rangeFinder)) { var fields = rangeFinder.GetRangeFinderDictionaryFields(pi.Name); foreach (var pair in fields) { if (!table.Columns.Contains(pair)) { table.Columns.Add(pair, typeof(Double)).SetGroup(pi.Name).SetDesc("Statistic from rangeFinder " + pi.Name).SetWidth(10); } } } else { removePi = false; } if (removePi && doRemoveReportedProperties) { plist.Remove(pi); } } return(table); }