CallCommonCode()
が呼び出されたときに属性コンストラクターを自動的に呼び出す方法はありますCodedMethod()
か?
using System;
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Struct,
AllowMultiple=false,Inherited=false)]
public class CallCommonCode : Attribute
{
public CallCommonCode() { Console.WriteLine("Common code is not called!"); }
}
public class ConcreteClass {
[CallCommonCode]
protected void CodedMethod(){
Console.WriteLine("Hey, this stuff does not work :-(");
}
public static void Main(string[] args)
{
new ConcreteClass().CodedMethod();
}
}