65.9K
CodeProject 正在变化。 阅读更多。
Home

一个简单的属性,用于存储许可信息和署名

starIconstarIconstarIconstarIconstarIcon

5.00/5 (6投票s)

2011 年 5 月 10 日

CPOL
viewsIcon

20243

几个字段用于存储提供的代码的一般信息

using System;
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public class AttributionAttribute : System.Attribute
{
    String _author;
    String _authorLink;
    String _contributionTitle;
    String _contributionLink;
    public AttributionAttribute()
    {
    }
    public String Author
    {
        get { return this._author; }
        set { this._author = value; }
    }
    public String AuthorLink
    {
        get { return this._authorLink; }
        set { this._authorLink = value; }
    }
    public String ContributionTitle
    {
        get { return this._contributionTitle; }
        set { this._contributionTitle = value; }
    }
    public String ContributionLink
    {
        get { return this._contributionLink; }
        set { this._contributionLink = value; }
    }
}
这使得向作者署名变得容易,而无需维护一个引用列表。
[assembly: Attribution
(
    Author = "Jani Giannoudis",
    AuthorLink = "http://www.itenso.com/en/Default.aspx",
    ContributionTitle = "User Settings Applied",
    ContributionLink = "https://codeproject.org.cn/KB/dotnet/user_settings.aspx"
)]
在通用的 DataGridView 中署名就像获取当前执行程序集及其所有引用的所有属性并求和一样简单;
foreach (AttributionAttribute aa in attribs)
{
  int newRowIdx = dataGridView1.RowCount;
  dataGridView1.RowCount++;
  dataGridView1[0, newRowIdx].Value = aa.Author;
  dataGridView1[0, newRowIdx].ToolTipText = aa.AuthorLink;
  dataGridView1[1, newRowIdx].Value = aa.ContributionTitle;
  dataGridView1[1, newRowIdx].ToolTipText = aa.ContributionLink;
}
尽情享受 :)
© . All rights reserved.