日期:2014-05-17 浏览次数:20898 次
public class CallContextAttribute : Attribute
{
public void SayHi(string abc) { }
}
[CallContext]
class WhereAreYouLocation
{
public void SayLocation()
{
//这里怎么表用上面标记头CallContext的SayHi方法
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class CallContextAttribute : Attribute
{
public void SayHi(string abc) { Console.WriteLine(abc); }
}
[CallContext]
class WhereAreYouLocation
{
public void SayLocation()
{
this.GetType().GetCustomAttributes(false)[0].GetType().GetMethod("SayHi").Invoke(this.GetType().GetCustomAttributes(false)[0], new object[] { "123" });
}
}
class Program
{
static void Main(string[] args)
{
new WhereAreYouLocation().SayLocation();
}
}
}