ふらっとC#,C♯,C#(初心者用) Part25
■ このスレッドは過去ログ倉庫に格納されています
0097デフォルトの名無しさん
2008/03/01(土) 23:20:22ちょっと作ってみた
public class MyAttribute : System.Attribute
{
public int IntData { get;set;}
public MyAttribute(int intData) { IntData = intData ; }
};
public class SumpleClass
{
[My(10)]
public int Field = 5 ;
};
void f(){
var tmp = new SumpleClass() ;
var attrs = tmp.GetType().GetField( "Field" ).GetCustomAttributes( false ) ;
for (int i = 0; i < attrs.GetLength(0); ++i)
{
var myattr = attrs[i] as MyAttribute ;
if (myattr == null) continue;
System.Console.WriteLine("{0}", myattr.IntData);
}
}
■ このスレッドは過去ログ倉庫に格納されています