Created
November 27, 2013 21:26
-
-
Save lsauer/7683528 to your computer and use it in GitHub Desktop.
C#: source-code header comments alternative by using attributes and runtime-reflection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//www.technical-programming.com, 2013 lo sauer | |
using System; | |
namespace MyProject.Attributes | |
{ | |
public enum CodeAttributeName { | |
Author, | |
Copyright, | |
RevisionHistory, | |
License, | |
Buildnumber, | |
Buildstatus, | |
//add your own... | |
} | |
//Use as follows | |
//[CodeAttribute()] | |
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)] | |
public class CodeAttribute : Attribute | |
{ | |
private CodeAttributeName name; | |
public object value; | |
public CodeAttribute(CodeAttributeName attributename, object attributevalue = null) | |
{ | |
this.name = attributename; | |
this.value = attributevalue; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//www.technical-programming.com, 2013 lo sauer | |
//Example Usage | |
[CodeAttribute(CodeAttributeName.Author, "[email protected]"), | |
CodeAttribute(CodeAttributeName.Author, "others credited in the code")] | |
[CodeAttribute(CodeAttributeName.Copyright, "lo sauer,2013")] | |
[CodeAttribute(CodeAttributeName.License, "MIT Licence")] | |
[CodeAttribute(CodeAttributeName.RevisionHistory, @" | |
ls,13-08-2011,0.11: Windows Shell Implementation | |
ls,13-11-2011,0.12: Fixed Win32API Message Hook | |
ls,13-11-2011,0.12: Fixed Dictionary Key Access | |
ls,13-11-2011,0.12: Added Markov(2n), Markov(3n) Methods for Entropy Calculation | |
")] | |
public partial class Program | |
{ | |
/// <summary> | |
/// Main entry point, short one-line description blabla... | |
/// </summary> | |
[STAThread] | |
static void Main() | |
{ | |
Console.WriteLine("Hello World #2312"); | |
Console.WriteLine( ((CodeAttribute)Attribute.GetCustomAttribute(typeof(Program), typeof(CodeAttribute))) | |
.RevisionHistory.ToString() | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <code-header> | |
// <author>[email protected]</author> | |
// <copyright>lo sauer,2013</copyright> | |
// <license>MIT Licence</license> | |
// <revisions> | |
// <revision initials="ls">Windows Shell Implementation </revision> | |
// <revision intiails="ls">Fixed Win32API Message Hook</revision> | |
// <revision intiails="ls">...</revision> | |
// </revisions> | |
// </code-header> | |
public partial class Program | |
{ | |
//.. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment