private static void WriteInvalidAttributes(PrintFile printFile, IEnumerable <PropertyInfo> properties, IEnumerable <string> attributes) { var list = attributes .Where(attribute => attribute != "xsd" && attribute != "xsi" && properties.All(x => x.Name != attribute)) .ToList(); if (list.Count == 0) { return; } printFile.WriteLine("The following attributes in the configuration file are invalid:"); printFile.IncrementIndent(); foreach (var item in list) { printFile.WriteLine("* {0}", item); } printFile.DecrementIndent(); printFile.WriteLine(); }
private static void WriteUnusedProperties(PrintFile printFile, IEnumerable <PropertyInfo> properties, IEnumerable <string> attributes) { var list = properties .Where(property => attributes.All(x => x != property.Name)) .Select(property => property.Name) .ToList(); if (list.Count == 0) { return; } printFile.WriteLine("The following properties in the configuration file where not set:"); printFile.IncrementIndent(); foreach (var item in list) { printFile.WriteLine("* {0}", item); } printFile.DecrementIndent(); printFile.WriteLine(); }
public void Write(Configuration configuration, PrintFile printFile) { var properties = typeof(Configuration).GetProperties(BindingFlags.Public | BindingFlags.Instance); if (_extension == ".xml") { WriteFromXml(printFile, properties); } if (_extension == ".properties") { WriteFromProperties(printFile, properties); } var list = properties .Select(property => { var value = property.GetValue(configuration, null); var metadata = property .GetCustomAttributes(typeof(MetadataAttribute), true) .Cast <MetadataAttribute>() .SingleOrDefault(); var description = metadata == null || string.IsNullOrEmpty(metadata.Value) ? property.Name.ToSentenceCase() : metadata.Value; string format; if (value == null) { format = string.Empty; } else { if (value is char) { var b = (byte)(char)value; format = string.Format("{0} - {1}", b, AsciiTable.GetDescription(b)); } else { format = value.ToString().Trim(); } } return(new { property.Name, Value = format, Description = description }); }) .ToList(); var maxKeyLength = list .Select(x => x.Name.Length) .Max(); var maxValueLength = list .Select(x => x.Value.Length) .Max(); foreach (var property in list) { printFile .WriteLine("{0}> {1} // {2}.", property.Name.PadLeft(maxKeyLength), property.Value.PadRight(maxValueLength), property.Description); } printFile.WriteLine(); }