오늘의 C# 공부 : 애트리뷰트, 다이나믹.

//———————————————————————-
//—————–애트리뷰트———————————
//———————————————————————-

//using System;

//namespace BasicAttribute
//{
//    class MyClass
//    {
//        [Obsolete(“OldMethod 는 폐기되었습니다. NewMethod() 를 이용하세요 “)]
//        public void OldMethod()
//        {
//            Console.WriteLine(“낡은거”);
//        }

//        public void NewMethod()
//        {
//            Console.WriteLine(“새거”);
//        }
//    }

//    class MainApp
//    {
//        static void Main(string[] args)
//        {
//            MyClass obj = new MyClass();

//            obj.OldMethod();
//            obj.NewMethod();
//        }
//    }
//}

////custom attribute

//using System;

//namespace HistoryAttribute
//{
//    [System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = true)]

//    class History : System.Attribute
//    {
//        private string programmer;
//        public double version;
//        public string changes;

//        public History(string programmer)
//        {
//            this.programmer = programmer;
//            version = 1.0;
//            changes = " First relese”;
//        }

//        public string GetProgrammer()
//        {
//            return programmer;
//        }
//    }

//    [History ( “Sean”, version = 0.1, changes = “2010-11-01 Created class stub”)]
//    [History ( “bob” , version = 0.2 , changes = " 2010-12-03 Added Func() Method”)]

//    class MyClass
//    {
//        public void Func()
//        {
//            Console.WriteLine(“Func()”);
//        }
//    }

//    class MainApp
//    {
//        static void Main (string[] args)
//        {
//            Type type = typeof(MyClass);
//            Attribute[] attribues = Attribute.GetCustomAttributes(type);
//            Console.WriteLine(“MyClass change history….”);

//            foreach (Attribute a in attribues)
//            {
//                History h = a as History;
//                if (h !=null)
//                    Console.WriteLine(“Ver:{0}, Programmer : {1}, Change: {2}",h.version,h.GetProgrammer(), h.changes);
//            }
//        }
//    }
//}

////////////////////////////////////////
//Dynamic 형식//////////////////////////
////////////////////////////////////////

using System;

namespace DuckTyping
{
    class Duck
    {
        public void Walk()
        {Console.WriteLine(this.GetType() + “.Walk”);}

        public void Swim()
        { Console.WriteLine(this.GetType() + “.Swim”); }

        public void Quack()
        { Console.WriteLine(this.GetType() + “.Quack”); }
    }

    class Mallard : Duck
    { }

    class Robot
    {
        public void Walk()
        { Console.WriteLine(“Robot.Walk”); }

        public void Swim()
        { Console.WriteLine(“Robot.Swim”); }

        public void Quack()
        { Console.WriteLine(“Robot.Quack”); }
    }

    class MainApp
    {
        static void Main(string[] args)
        {
            dynamic[] arr = new dynamic[] {new Duck(), new Mallard(), new Robot()};

            foreach (dynamic duck in arr)
            {
                Console.WriteLine(duck.GetType());
                duck.Walk();
                duck.Swim();
                duck.Quack();

                Console.WriteLine();
            }
        }
    }
}

Hugo로 만듦
JimmyStack 테마 사용 중