/// <summary>Gets C# code lines to be inserted before property declaration</summary> /// <param name="property">The property.</param> /// <param name="flags">The flags.</param> /// <returns>List with C# code lines declaring attributes and XML documentation</returns> public static List <String> GetPropertyCodeInsertLines(this settingsPropertyEntry property, PropertyAppendFlags flags = PropertyAppendFlags.setAll) { List <String> inserts = new List <string>(); if (flags.HasFlag(PropertyAppendFlags.setComponentModelAttributes)) { inserts.Add($"[Category(\"{property.categoryName}\")]"); inserts.Add($"[DisplayName(\"{property.displayName}\")]"); inserts.Add($"[Description(\"{property.description}\")]"); } if (flags.HasFlag(PropertyAppendFlags.setXmlSerializationAttributes)) { if (property.IsXmlIgnore) { inserts.Add($"[XmlIgnore]"); } } if (flags.HasFlag(PropertyAppendFlags.setSCIReportingDefinitions)) { if (!property.escapeValueString) { inserts.Add($"[imb(imbAttributeName.reporting_escapeoff)]"); } if (!property.letter.isNullOrEmpty()) { inserts.Add($"[imb(imbAttributeName.measure_letter, \"{property.letter}\")]"); } if (!property.unit.isNullOrEmpty()) { inserts.Add($"[imb(imbAttributeName.measure_setUnit, \"{property.unit}\")]"); } if (!property.format.isNullOrEmpty()) { inserts.Add($"[imb(imbAttributeName.reporting_valueformat, \"{property.format}\")]"); } if (property.width != 0) { inserts.Add($"[imb(imbAttributeName.reporting_columnWidth, {property.width})]"); } if (property.isHiddenInReport) { inserts.Add($"[imb(imbAttributeName.reporting_hide)]"); } if (!property.color.isNullOrEmpty()) { inserts.Add($"[imb(imbAttributeName.basicColor, \"{property.color}\")]"); } if (property.Alignment != textCursorZoneCorner.none) { inserts.Add($"[imb(templateFieldDataTable.col_alignment, textCursorZoneCorner.{property.Alignment})]"); } } if (flags.HasFlag(PropertyAppendFlags.setXmlDocumentation)) { inserts.Add("/// <summary>"); inserts.Add($"/// {property.description}"); inserts.Add("/// </summary>"); } return(inserts); }
/// <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); }