电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

自定义反射的示例


发布日期:2022/12/13
 

using System;

using SystemCollectionsGeneric;

using SystemLinq;

using SystemText;

using SystemReflection;

namespace attribute

{

class Program

{

static void Main(string[] args)

{

Tester t = new Tester();

tCannotRun();

Type tp = typeof(Tester);

MethodInfo methodinfo = tpGetMethod(CannotRun);

TestAttribute myatt = (TestAttribute)AttributeGetCustomAttribute(methodinfo typeof(TestAttribute));

myattRunTest();

}

}

class Tester

{

[Test(Error Here)]

public void CannotRun()

{

ConsoleWriteLine(fuck this is a error);

}

}

[AttributeUsage(AttributeTargetsClass | AttributeTargetsMethod Inherited = true)]

public class TestAttribute : SystemAttribute

{

public TestAttribute(string name)

{

ConsoleWriteLine(name);

}

public void RunTest()

{

ConsoleWriteLine(test here);

}

}

}

上一篇:构建可反转排序泛型字典类(2)--排序方向

下一篇:支持ESMTP身份验证的邮件发送