zoukankan      html  css  js  c++  java
  • [原创]反射,.NET,委托 Virus

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Configuration;
    using System.Reflection;

    namespace ConsoleApp
    {
        public delegate string dele(string str);

        public class Bmw
        {
            private static int idata;
            private char cdata;
            public static string sdata;
            public double ddata;

            public Bmw()
            { }
            public Bmw(int i)
            {
                idata = i;
            }
            private Bmw(char c)

            {
                cdata = c;
            }

            public char Cdata
            {
                get
                { return cdata; }
                set
                { cdata = value; }
            }

            private string Ha()
            {
                Console.WriteLine("haha");
                return "";
            }

            public string Display(string str)
            {
                return "asdf";
            }

            public void Drive()
            {
                Console.WriteLine("drive bmw..");
            }
        }

        class Program
        {     
            static void Main()
            {
               
                //Assembly.Load().CreateInstance()
                Assembly a = Assembly.LoadFrom("ConsoleApp.exe");
                Type[] mytypes = a.GetTypes();

                Console.WriteLine("these types are included...");

                foreach (Type t in mytypes)
                {
                    System.Console.WriteLine(t.Name);
                }

                Type ht = typeof(Bmw);

                Console.WriteLine("these methods are included..");

                MethodInfo[] info = ht.GetMethods();

                foreach (MethodInfo m in info)
                {
                    Console.WriteLine(m.Name);
                }

                ConstructorInfo[] consinfo = ht.GetConstructors();
                Console.WriteLine(".................................................");
                Console.WriteLine("constructor is");
                foreach (ConstructorInfo c in consinfo)
                {
                    Console.WriteLine(c.Name);
                }

                EventInfo[] einfo = ht.GetEvents();
                Console.WriteLine(".................................................");
                Console.WriteLine("event is");
                foreach (EventInfo e in einfo)
                {
                    Console.WriteLine(e.Name);
                }

                FieldInfo[] finfo = ht.GetFields();
                Console.WriteLine(".................................................");
                Console.WriteLine("field is");
                foreach (FieldInfo f in finfo)
                {
                    Console.WriteLine(f.Name);
                }

                MemberInfo[] minfo = ht.GetMembers();
                Console.WriteLine(".................................................");
                Console.WriteLine("member is");
                foreach (MemberInfo m in minfo)
                {
                    Console.WriteLine(m.Name);
                }

                PropertyInfo[] pinfo = ht.GetProperties();
                Console.WriteLine(".................................................");
                Console.WriteLine("property is");
                foreach (PropertyInfo p in pinfo)
                {
                    Console.WriteLine(p.Name);
                }

                Console.WriteLine(ht.GetMethod("Display").ToString());

                Bmw B=new Bmw();

                dele del = new dele(B.Display);

                Console.WriteLine(del("dd"));
                //Car car = Drive.DriveCar("benz");
                //car.Drive();
                Console.ReadLine();
                //System.Collections.Generic.
            }
        }
    }

    【Blog】http://virusswb.cnblogs.com/

    【MSN】jorden008@hotmail.com

    【说明】转载请标明出处,谢谢

    反馈文章质量,你可以通过快速通道评论:

  • 相关阅读:
    执行 composer --version 命令的时候报 Your requirements could not be resolved to an installable set of packages. 错误
    Mac 解决每次新建终端 都要重新运行 source ~/.bash_profile问题
    mac 文件根据权限展示颜色
    Unable to negotiate with 180.101.**.*** port 22: no matching cipher found. Their offer: 3des-cbc,blowfish-cbc,arcfour,cast128-cbc,aes128-cbc,aes192-cbc,aes256-cbc
    带有git账户名称密码更改git推送拉取地址
    使用Java,实现图片与Base64编码互转的程序
    Spring事务管理:ACID的概念,Spring事务管理核心接口,基于XML方式的声明式事务、基于注解(Annotation)方式的声明式事务
    Spring,JDBC, JdbcTemplate的常用方法
    Spring,AOP,基于注解声明式ApsectJ
    养猫记
  • 原文地址:https://www.cnblogs.com/virusswb/p/856991.html
Copyright © 2011-2022 走看看