Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / attributes

A simple attribute to store licensing information and credits

5.00/5 (6 votes)
10 May 2011CPOL 20K  
A few fields to store general information on the provided code
C#
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; }
    }
}

This makes it easy to give credit to the author, without having to keep a list of what's referenced and whatsnot.
C#
[assembly: Attribution
(
    Author = "Jani Giannoudis",
    AuthorLink = "http://www.itenso.com/en/Default.aspx",
    ContributionTitle = "User Settings Applied",
    ContributionLink = "http://www.codeproject.com/KB/dotnet/user_settings.aspx"
)]

Giving credit in a generic DataGridView is as easy as fetching all attributes from the current executing assembly and all it's references and summing them;
C#
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;
}

Enjoy :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)