I personally really like the implementation of lance Larsen and his static AssemblyInfo class.
One basically pastes the class in his assembly (I usually use the already existing AssemblyInfo.cs file as it fits naming convention)
The code to paste is:
internal static class AssemblyInfo
{
public static string Company { get { return GetExecutingAssemblyAttribute<AssemblyCompanyAttribute>(a => a.Company); } }
public static string Product { get { return GetExecutingAssemblyAttribute<AssemblyProductAttribute>(a => a.Product); } }
public static string Copyright { get { return GetExecutingAssemblyAttribute<AssemblyCopyrightAttribute>(a => a.Copyright); } }
public static string Trademark { get { return GetExecutingAssemblyAttribute<AssemblyTrademarkAttribute>(a => a.Trademark); } }
public static string Title { get { return GetExecutingAssemblyAttribute<AssemblyTitleAttribute>(a => a.Title); } }
public static string Description { get { return GetExecutingAssemblyAttribute<AssemblyDescriptionAttribute>(a => a.Description); } }
public static string Configuration { get { return GetExecutingAssemblyAttribute<AssemblyConfigurationAttribute>(a => a.Configuration); } }
public static string FileVersion { get { return GetExecutingAssemblyAttribute<AssemblyFileVersionAttribute>(a => a.Version); } }
public static Version Version { get { return Assembly.GetExecutingAssembly().GetName().Version; } }
public static string VersionFull { get { return Version.ToString(); } }
public static string VersionMajor { get { return Version.Major.ToString(); } }
public static string VersionMinor { get { return Version.Minor.ToString(); } }
public static string VersionBuild { get { return Version.Build.ToString(); } }
public static string VersionRevision { get { return Version.Revision.ToString(); } }
private static string GetExecutingAssemblyAttribute<T>(Func<T, string> value) where T : Attribute
{
T attribute = (T)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(T));
return value.Invoke(attribute);
}
}
You add a using System; to the top of the file and you're good to go.
For my applications i use this class to set/get/work with my local users settings using:
internal class ApplicationData
{
DirectoryInfo roamingDataFolder;
DirectoryInfo localDataFolder;
DirectoryInfo appDataFolder;
public ApplicationData()
{
appDataFolder = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AssemblyInfo.Product,"Data"));
roamingDataFolder = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),AssemblyInfo.Product));
localDataFolder = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AssemblyInfo.Product));
if (!roamingDataFolder.Exists)
roamingDataFolder.Create();
if (!localDataFolder.Exists)
localDataFolder.Create();
if (!appDataFolder.Exists)
appDataFolder.Create();
}
/// <summary>
/// Gets the roaming application folder location.
/// </summary>
/// <value>The roaming data directory.</value>
public DirectoryInfo RoamingDataFolder => roamingDataFolder;
/// <summary>
/// Gets the local application folder location.
/// </summary>
/// <value>The local data directory.</value>
public DirectoryInfo LocalDataFolder => localDataFolder;
/// <summary>
/// Gets the local data folder location.
/// </summary>
/// <value>The local data directory.</value>
public DirectoryInfo AppDataFolder => appDataFolder;
}
Have a look at Larsens website (MVP), he has cool stuff to draw Inspiration from.