Mình cũng chưa hiểu rõ về cái namespace này lắm (muốn tìm hiểu nhưng chắc đợi thi xong). Mình thường sử dụng nó để lấy một vài thông số hệ thống và thông số của các file config của chương trình.
Thường lấy ra productname, version mà khi ta tạo chương trình và thiết lập trong phần Project --> [tên chương trình] properties của visualstudio.
Dưới đây là file kèm mình tham khảo và thường sử dụng cách này để hiển thị version, productname, companyname, copyright...
Code:
using System.Reflection;
namespace QLDiemHV
{
public partial class frmAbout : Form
{
public frmAbout(frmMain parent)
{
InitializeComponent();
this.MdiParent = parent;
this.Text = String.Format("About {0}", AssemblyTitle);
lbProductName.Text = AssemblyProduct;
lbVersion.Text = String.Format("Version {0}", AssemblyVersion);
//lbCompanyName.Text = AssemblyCompany;
//lbCopyRight.Text = AssemblyCopyright;
//txtDescription.Text = AssemblyDescription;
}
#region Singleton
static frmAbout me = null;
static public frmAbout GetObj(frmMain frm)
{
if (me == null)
{
me = new frmAbout(frm);
}
return me;
}
#endregion
#region Assembly Attribute Accessors
public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
return titleAttribute.Title;
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
return "";
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
return "";
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
return "";
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
return "";
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion
}
}
http://msdn2.microsoft.com/en-us/lib...83(VS.80).aspx
http://www.oreilly.com/catalog/progc...pter/ch18.html