熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

自定義反射的示例

2022-06-13   來源: .NET編程 

   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);

           }

       }

   }


From:http://tw.wingwit.com/Article/program/net/201311/13702.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.