I am looking for generic ideas and guidelines of how to improve the style of my coding and make it more readable and robust.
public class TemplatePart : ITemplatePart
{
#region Fields
private readonly List<ITemplatePart> _options = new List<ITemplatePart>();
private readonly List<ITemplatePart> _cables = new List<ITemplatePart>();
#endregion // Fields
#region Constructor
#endregion // Constructor
#region Creator
public static TemplatePart CreateTemplatePart(string partName, string basePart)
{
return new TemplatePart
{
PartName = partName,
BasePart = basePart
};
}
public static TemplatePart CreateTemplatePart(DataTable table, DataRow row, int rowIndex)
{
return new TemplatePart
{
// as you can see, TrimSideSpaces() get's applied for every single content
// being read from the sheet for each property.
Key = rowIndex,
PartName = TrimSideSpaces(row.Field<string>(Strings.TemplateSpreadSheet_Column_PartName)),
BasePart = TrimSideSpaces(row.Field<string>(Strings.TemplateSpreadSheet_Column_BasePart)),
Category = TrimSideSpaces(ExtractVendor(table.TableName))
};
}
private static string TrimSideSpaces(string p)
{
var rgx = new Regex(@"\S.*\S");
return rgx.Match(p).Value;
}
#endregion // Creator
#region Public Properties
public int Key { get; set; }
public string PartName { get; set; }
public string BasePart { get; set; }
// This captures the tab the item is in.
public string Category { get; set; }
public double? PriceDom { get; set; }
public double? PriceInt { get; set; }
public IEnumerable<ITemplatePart> Options { get { return this._options; } }
public IEnumerable<ITemplatePart> Cables { get { return this._cables; } }
#endregion // Public Properties
#region Private Helpers
....
#endregion // Private Helpers
}
I have a similar concrete class with about 20 properties and I am thinking it might not be a good choice to apply methods on each property such as TrimSideSpaces()
in this example.
I apologize if this is not a whole code which could compile.