in

@Prog! - ASP.NET(C#) AJAX -

ASP.NET(C#) 2.0 & ASP.NET Ajax (ATLAS) のメモ書き

カスタム属性を収得する(System.Attribute)

最新の投稿は、投稿日時: 2008/01/10 15:43 投稿者: ASANO です。スレッドには 0 件の返答があります。
ページ 1 / 1 (1 アイテム)
投稿の並べ替え: 前へ 次へ
  • 2008/01/10 15:43

    カスタム属性を収得する(System.Attribute)

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

    namespace TestConsoleApplication
    {
        class Program
        {
            [AttributeUsage(AttributeTargets.Property)]
            public class ColumnMappingAttribute : System.Attribute
            {
                private string _name;
                public ColumnMappingAttribute(string name)
                {
                    _name = name;
                }
                public string Name
                {
                    get { return _name; }
                }
            }

            public class MyClass
            {
                [ColumnMapping("ItemNbr")]
                public int ItemNbr
                {
                    get { return 0; }
                }
            }

            static void Main(string[ args)
            {
                MyClass myClass = new MyClass();
                object[ o = myClass.GetType().GetProperty("ItemNbr").GetCustomAttributes(false);

                Console.WriteLine(((ColumnMappingAttribute)o[0]).Name);

               
                Console.Read();
            }
        }
    }

ページ 1 / 1 (1 アイテム)