Saturday, 11 May 2013

Write a program, to create two custom attributes, BugFixingAttribute and DescriptionAttribute, to be assigned to class members. Add the two attributes together in a single application.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Attribute_example
{
        [AttributeUsage(AttributeTargets.Class|AttributeTargets.Constructor|AttributeTargets.Field|AttributeTargets.Method|AttributeTargets.Property,AllowMultiple=true)]
        public class BugFixingAttribute:System.Attribute
        {
            private int bugNo;
            private string developer;
            private string dataFixed;
            public string remarks;
            public BugFixingAttribute(int BugNo,string Developer,string DataFixed)
            {
                this.bugNo=BugNo;
                this.developer=Developer;
                this.dataFixed=DataFixed;
            }
            public int BugNo
            {
                get
                {
                    return bugNo;
                }
            }
            public string DataFixed
            {
                get
                {
                    return dataFixed;
                }
            }
            public string Developer
            {
                get
                {
                    return Developer;
                }
            }
            public string Remarks
            {
                get
                {
                    return remarks;
                }
               set
                {
                    remarks= value;
                }
            }
        }
        [BugFixingAttribute(125,"Sara Levo","18/06/2012",Remarks="Return object not specified")]
        public class Calculator
        {
            public double Add(Double num1,Double num2)
            {
                return num1+num2;
            }
            public double subtract(Double num1,Double num2)
            {
                return num1-num2;
            }
            [BugFixingAttribute(155,"Sara Levo","20/06/2012")]
            public double Divide(Double num1,Double num2)
            {
                return num1*num2;
                ;
            }
            [BugFixingAttribute(156, "Sara Levo", "20/06/2012")]
            public double divide(Double num1, Double num2)
            {
                return num1 / num2;
            }
        }
        public class EntryPoint
        {
       public static void Main()
        {
            Calculator Myobj=new Calculator();
            Console.WriteLine("The sum of specified two nos are:{0}",Myobj.Add(15,20.5));
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment