1/**
2 * Copyright(C) 2004
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 2004.
11 * @author : Salih Yurttas, Yi Yang.
12 */
13
14
15using System;
16using System.Reflection;
17
18namespace Attibute00
19{
20
21 // create custom attribute to be assigned to class members
22 [AttributeUsage(AttributeTargets.Class |
23 AttributeTargets.Constructor |
24 AttributeTargets.Field |
25 AttributeTargets.Method |
26 AttributeTargets.Property,
27 AllowMultiple = true)]
28 public class BugFixAttribute : System.Attribute
29 {
30 // private member data
31 private int bugID;
32 private string comment;
33 private string date;
34 private string programmer;
35
36 // attribute constructor for
37 // positional parameters
38 public BugFixAttribute(int bugID, string programmer, string date)
39 {
40 this.bugID = bugID;
41 this.programmer = programmer;
42 this.date = date;
43 }
44
45 // accessor
46 public int BugID
47 {
48 get
49 {
50 return bugID;
51 }
52 }
53
54 // property for named parameter
55 public string Comment
56 {
57 get
58 {
59 return comment;
60 }
61 set
62 {
63 comment = value;
64 }
65 }
66
67 // accessor
68 public string Date
69 {
70 get
71 {
72 return date;
73 }
74 }
75
76 // accessor
77 public string Programmer
78 {
79 get
80 {
81 return programmer;
82 }
83 }
84 }
85
86 // ********* assign the attributes to the class ********
87 [BugFixAttribute(100,"SY","01/03/03")]
88 [BugFixAttribute(107,"Haiwen","01/04/04", Comment="Fixed off by one errors")]
89 [BugFixAttribute(103,"Yi","07/31/04", Comment="Fix one bug in class A00")]
90 public class A00
91 {
92 [BugFixAttribute(103,"Yi","08/01/04", Comment="Fix the bug in function DoFun1")]
93 public double DoFunc1(double p1)
94 {
95 return p1 + DoFunc2(p1);
96 }
97
98 public double DoFunc2(double p1)
99 {
100 return p1/3;
101 }
102 }
103
104 public class Test00
105 {
106
107 public static void PrintAttributes1(BugFixAttribute bfa)
108 {
109 Console.WriteLine("BugID: {0}", bfa.BugID);
110 Console.WriteLine("Programmer: {0}", bfa.Programmer);
111 Console.WriteLine("Date: {0}", bfa.Date);
112 Console.WriteLine("Comment: {0}", bfa.Comment);
113 }
114
115 /*public static void Main(string[] args)
116 {
117 // get the member information and use it to
118 // retrieve the custom attributes
119 MemberInfo inf = typeof(Sample);
120 object[] attributes;
121 attributes = inf.GetCustomAttributes(typeof(BugFixAttribute), false);
122
123 //print out the attributes for class
124 Console.WriteLine("printing class attributes");
125 foreach(Object attribute in attributes)
126 {
127 PrintAttributes((BugFixAttribute)attribute);
128 }
129
130 //get the csutomer attributes for the methods
131 Type theType = Type.GetType("AttibuteSample.Sample");
132 MemberInfo[] methodInfo = theType.GetMembers();
133
134 //print out the attributes for member if have
135 Console.WriteLine("\nprinting member attributes");
136 foreach(MemberInfo info in methodInfo)
137 {
138 attributes = info.GetCustomAttributes(false);
139 foreach(object attribute in attributes)
140 PrintAttributes((BugFixAttribute)attribute);
141 }
142 }*/
143 }
144
145}