using System.Collections.Generic; using System.Linq; using System.Reflection; namespace Console.Waterworks.Specialists { class ProgramInfoSpecialist { internal List GatherProgramInfomation() { var info = new List() { addProductLine(), addCompanyLine(), addCopyRightLine(), addProductDescription() }; return info; } private string addCopyRightLine() { Assembly assembly = Assembly.GetEntryAssembly(); var copyRightAttribute = assembly .GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false) .OfType() .FirstOrDefault(); return (copyRightAttribute != null) ? copyRightAttribute.Copyright : null; } string addProductLine() { var name = GetProductName(); var buildInfo = getBuildInfo(); return (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(buildInfo)) ? $"{name} {buildInfo}" : null; } string addCompanyLine() { Assembly assembly = Assembly.GetEntryAssembly(); var companyAttribute = assembly .GetCustomAttributes(typeof(AssemblyCompanyAttribute), false) .OfType() .FirstOrDefault(); return (companyAttribute != null) ? companyAttribute.Company : null; } string addProductDescription() { Assembly assembly = Assembly.GetEntryAssembly(); var descriptionAttribute = assembly .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false) .OfType() .FirstOrDefault(); return (descriptionAttribute != null) ? descriptionAttribute.Description : null; } internal string GetProductName() { Assembly assembly = Assembly.GetEntryAssembly(); var productAttribute = assembly .GetCustomAttributes(typeof(AssemblyProductAttribute), false) .OfType() .FirstOrDefault(); return (productAttribute != null) ? productAttribute.Product : null; } string getBuildInfo() => Assembly.GetEntryAssembly().GetName().Version.ToString(); } }