A NuGet package. It aim is to help you write extendable and command-based console programs in C# and .Net.
https://www.craigoates.net/Software/Project/7
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.5 KiB
70 lines
2.5 KiB
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Reflection; |
|
|
|
namespace Console.Waterworks.Specialists |
|
{ |
|
class ProgramInfoSpecialist |
|
{ |
|
internal List<string> GatherProgramInfomation() |
|
{ |
|
var info = new List<string>() |
|
{ |
|
addProductLine(), |
|
addCompanyLine(), |
|
addCopyRightLine(), |
|
addProductDescription() |
|
}; |
|
return info; |
|
} |
|
|
|
private string addCopyRightLine() |
|
{ |
|
Assembly assembly = Assembly.GetEntryAssembly(); |
|
var copyRightAttribute = assembly |
|
.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false) |
|
.OfType<AssemblyCopyrightAttribute>() |
|
.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<AssemblyCompanyAttribute>() |
|
.FirstOrDefault(); |
|
return (companyAttribute != null) ? companyAttribute.Company : null; |
|
} |
|
|
|
string addProductDescription() |
|
{ |
|
Assembly assembly = Assembly.GetEntryAssembly(); |
|
var descriptionAttribute = assembly |
|
.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false) |
|
.OfType<AssemblyDescriptionAttribute>() |
|
.FirstOrDefault(); |
|
return (descriptionAttribute != null) ? descriptionAttribute.Description : null; |
|
} |
|
|
|
internal string GetProductName() |
|
{ |
|
Assembly assembly = Assembly.GetEntryAssembly(); |
|
var productAttribute = assembly |
|
.GetCustomAttributes(typeof(AssemblyProductAttribute), false) |
|
.OfType<AssemblyProductAttribute>() |
|
.FirstOrDefault(); |
|
return (productAttribute != null) ? productAttribute.Product : null; |
|
} |
|
|
|
string getBuildInfo() => Assembly.GetEntryAssembly().GetName().Version.ToString(); |
|
} |
|
}
|
|
|