smartsdr-dsp/pc/CODEC2 GUI/CODEC2 GUI/AssemblyInfo.cs

120 lines
3.7 KiB
C#

/*******************************************************************************
* AssemblyInfo.cs
*
* Helper class that holds Assembly Info
*
* Created on: 2015-08-23
* Author: Mark Hanson / AA3RK / MKCM Software, LLC.
*
*
*******************************************************************************
*
* Copyright (C) 2015 FlexRadio Systems.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact: gpl<AT>flexradio<DOT>com or
*
* GPL C/O FlexRadio Systems
* 4616 W. Howard Lane
* Suite 1-150
* Austin, TX USA 78728
*
******************************************************************************/
using System;
using System.IO;
using System.Reflection;
namespace CODEC2_GUI
{
public class AssemblyInfo
{
public AssemblyInfo(Assembly assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
this.assembly = assembly;
}
private readonly Assembly assembly;
/// <summary>
/// Gets the title property
/// </summary>
public string ProductTitle
{
get
{
return GetAttributeValue<AssemblyTitleAttribute>(a => a.Title,
Path.GetFileNameWithoutExtension(assembly.CodeBase));
}
}
/// <summary>
/// Gets the application's version
/// </summary>
public string Version
{
get
{
string result = string.Empty;
Version version = assembly.GetName().Version;
if (version != null)
return version.ToString();
else
return "1.0.0.0";
}
}
/// <summary>
/// Gets the description about the application.
/// </summary>
public string Description
{
get { return GetAttributeValue<AssemblyDescriptionAttribute>(a => a.Description); }
}
/// <summary>
/// Gets the product's full name.
/// </summary>
public string Product
{
get { return GetAttributeValue<AssemblyProductAttribute>(a => a.Product); }
}
/// <summary>
/// Gets the copyright information for the product.
/// </summary>
public string Copyright
{
get { return GetAttributeValue<AssemblyCopyrightAttribute>(a => a.Copyright); }
}
/// <summary>
/// Gets the company information for the product.
/// </summary>
public string Company
{
get { return GetAttributeValue<AssemblyCompanyAttribute>(a => a.Company); }
}
protected string GetAttributeValue<TAttr>(Func<TAttr,
string> resolveFunc, string defaultResult = null) where TAttr : Attribute
{
object[] attributes = assembly.GetCustomAttributes(typeof(TAttr), false);
if (attributes.Length > 0)
return resolveFunc((TAttr)attributes[0]);
else
return defaultResult;
}
}
}