public void AppendProperty(settingsPropertyEntry property, PropertyAppendType type, PropertyAppendFlags flags) { String def_value = ""; if (flags.HasFlag(PropertyAppendFlags.setDefaultValue)) { if (property.type.IsValueType) { def_value = " = default(" + property.type + ");"; } else { if (property.type.GetConstructor(new Type[] { }) != null) { def_value = " = new " + property.type + "();"; } else { def_value = " = default(" + property.type + ");"; } } def_value = def_value.Replace(" ", " ").Trim(); } else { } List <String> inserts = property.GetPropertyCodeInsertLines(flags); switch (type) { case PropertyAppendType.autoproperty: foreach (var l in inserts) { AppendLine(l); } String apl = "public " + property.name + " {get;set;} " + def_value; if (def_value != "") { apl = apl.ensureEndsWith(";"); } apl = apl.Replace(" ", " "); AppendLine(apl); break; case PropertyAppendType.backingField: AppendLine("protected " + property.relevantTypeName + " _" + property.name + " " + def_value.ensureEndsWith(";")); foreach (var l in inserts) { AppendLine(l); } AppendLine("public " + property.relevantTypeName + " " + property.name + ""); open(CodeBlockType.codeBlock); AppendGetSetBlock(property.name, true, true); close(CodeBlockType.codeBlock); break; } }
/// <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); }