当前位置: 首页>>代码示例>>C#>>正文


C# Program.GetType方法代码示例

本文整理汇总了C#中Program.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Program.GetType方法的具体用法?C# Program.GetType怎么用?C# Program.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Program的用法示例。


在下文中一共展示了Program.GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static int Main(string[] args)
        {
			List<string> str = null;
	  
			object[] methodArgs = new object[] { str };
	  
			Program p = new Program();
			p.GetType().GetMethod("TestMethod").Invoke(p, methodArgs);

			/* Byref nullable tests */
			object[] a = new object [1];
			int? i = 5;
			object o = i;
			a [0] = o;
			typeof (Program).GetMethod ("TestMethodNullable").Invoke (p, a);
			if ((int)a [0] != 6)
				return 1;
			if ((int)o != 5)
				return 2;

			a [0] = null;
			typeof (Program).GetMethod ("TestMethodNullable").Invoke (p, a);
			if ((int)a [0] != 0)
				return 3;

			return 0;
        }
开发者ID:Zman0169,项目名称:mono,代码行数:27,代码来源:generics-invoke-byref.2.cs

示例2: Main

 static void Main()
 {
     int s = 20;
     GetAString firstStringMethod = new GetAString(s.ToString);
     Console.WriteLine(firstStringMethod());
     Console.WriteLine(firstStringMethod.Invoke());
     sbyte o = 127;
     //checked { ++o; }
     ++o;
     Console.WriteLine(o);
     int r=9;
     Console.WriteLine(R(ref r));
     Console.WriteLine(DayOfWeek.Friday);
     Console.WriteLine(r);
     int z;
     Console.WriteLine("z+a=out "+ F(out z));
     const int n = 6;
     int c = 4;
     Program p = new Program();
     Console.WriteLine("gET tYPE: "+p.GetType(), p.MemberwiseClone());
     Console.WriteLine(p._a);
     Console.WriteLine(b);
     Console.WriteLine(c);
     Console.WriteLine(c.GetType());
     //Console.WriteLine(F());
     for(int i = 0; i < 3; i++)
     {
         int d = 5;
         Console.WriteLine(d);
     }
     //Console.ReadLine();
     return;
 }
开发者ID:jaysazanov,项目名称:JSONSerializer,代码行数:33,代码来源:Program.cs

示例3: doOperation

 public static string doOperation(string operationName, int numb1, int numb2)
 {
     object[] mParam = new object[] { numb1, numb2 };
     Program myProgram = new Program();
     Type myType = myProgram.GetType();
     //Type myType = typeof(Program);
     MethodInfo myMethodInfo = myType.GetMethod(operationName);
     return myMethodInfo.Invoke(myProgram, mParam).ToString();
 }
开发者ID:DriesPeeters,项目名称:examprep-70_483,代码行数:9,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            List<string> str = null;

              object[] methodArgs = new object[] { str };

              Program p = new Program();
              p.GetType().GetMethod("TestMethod").Invoke(p, methodArgs);
        }
开发者ID:robertmichaelwalsh,项目名称:Multilex,代码行数:9,代码来源:generics-invoke-byref.2.cs

示例5: GetRoles

        static string GetRoles(string methodName)
        {
            Program a = new Program();            
            //MethodInfo method = a.GetType().GetMethod(methodName);            
            MethodInfo me = a.GetType().GetMethod(methodName);

            MethodInfo[] arrMethod = typeof(Program).GetMethods();
            MethodInfo method = null;
            foreach (MethodInfo m in arrMethod)
            {
                if (m.Name == methodName) method = m;
            }

            method = me;
            AuthorizeAttribute[] arrAttr = (AuthorizeAttribute[])method
                .GetCustomAttributes(typeof(AuthorizeAttribute),true);

            if (arrAttr.Count() == 0)
                return "";
            else
                return arrAttr[0].Roles;            
        }
开发者ID:vramsngrai1994,项目名称:mkpacific-ltd,代码行数:22,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            const int maxAttempt = 1000000;
            var stopwatch = new Stopwatch();

            #region Normal Invocation
            var prog = new Program();
            stopwatch.Start();
            for (int i = 0; i < maxAttempt; i++) {
                prog.Foo();
            }
            stopwatch.Stop();
            Console.WriteLine("Toma {0} mill", stopwatch.ElapsedMilliseconds);
            #endregion

            #region Using Reflection
            Type t = prog.GetType();
            stopwatch.Restart();
            for (int i = 0; i < maxAttempt; i++) {
                t.InvokeMember("Foo", BindingFlags.InvokeMethod, null, prog, new object[] { });
            }
            stopwatch.Stop();
            Console.WriteLine("Toma {0} mill", stopwatch.ElapsedMilliseconds);
            #endregion

            #region Dynamic Invocation
            dynamic dynamicProg = prog;

            stopwatch.Restart();
            for (int i = 0; i < maxAttempt; i++) {
                dynamicProg.Foo();
            }
            stopwatch.Stop();
            Console.WriteLine("Toma {0} mill", stopwatch.ElapsedMilliseconds);
            #endregion

            Console.ReadKey();
        }
开发者ID:hdiazvertical,项目名称:PerformaceDataTypes,代码行数:38,代码来源:Program.cs

示例7: Main

        static int Main(string[] args)
        {
            Console.WriteLine("MultiplayerOnlineGame - BuildData Tool");
             Console.WriteLine();

             if (args.Length != 3)
             {
            Console.WriteLine("Error: Must provide 3 arguments:");
            Console.WriteLine("BuildData.exe ConfigFile.cfg SourcePath\\ OutputPath\\");
            return 1;
             }

             var p = new Program();
             p.ConfigFile = args[0];
             p.SourcePath = args[1];
             p.OutputPath = args[2];
             p.AppPath = Path.GetDirectoryName(p.GetType().Assembly.Location);

             if (!Directory.Exists(p.OutputPath))
            Directory.CreateDirectory(p.OutputPath);

             Console.WriteLine("ConfigFile: {0}", p.ConfigFile);
             Console.WriteLine("SourcePath: {0}", p.SourcePath);
             Console.WriteLine("OutputPath: {0}", p.OutputPath);
             Console.WriteLine();

             try
             {
            p.Run();
            return 0;
             }
             catch (Exception ex)
             {
            Console.WriteLine("Error: " + ex.Message);
            Console.WriteLine("Exiting.");
            return 1;
             }
        }
开发者ID:vividos,项目名称:MultiplayerOnlineGame,代码行数:38,代码来源:Program.cs

示例8: Main

 static void Main()
 {
     Console.Title = "";
     var p = new Program();
     var mi = ct(p.GetType());
     var mi1 = mi.ReflectedType.GetMethods().FirstOrDefault(mt => mt.Name == mi.Name && mt.GetParameters().Length != mi.GetParameters().Length);
     var en = Val().GetEnumerator();
     try
     {
         while (true)
         {
             mi1.Invoke(null, BindingFlags.Static, null, en.Val(), CultureInfo.CurrentCulture);
         }
     }
     catch (Exception ex)
     {
     }
     finally
     {
         Console.ReadKey();
     }
 }
开发者ID:RELEX-Group,项目名称:public,代码行数:22,代码来源:RELEX_NewYear_2017.cs

示例9: Main

        static void Main(string[] args)
        {
            const string dllPath = @"F:\黑马教学资料\CSharp知识点总结\反射测试的dll\bin\Debug\反射测试的dll.dll";

            //
            Assembly assembly = Assembly.LoadFile(dllPath);//路径要求全路径

            #region 反射测试dll中包含的类型

            //foreach (Type exportedType in assembly.GetExportedTypes())
            //{
            //    Console.WriteLine(exportedType.ToString());
            //}

            //Module[] modules = assembly.GetModules();

            //foreach (Module module in modules)
            //{
            //    Console.WriteLine(module.ToString());
            //}

            //var  moduleList = assembly.Modules;

            //foreach (Module module in moduleList)
            //{
            //    Console.WriteLine(module.ToString());
            //}

            //moduleList=assembly.GetLoadedModules();

            //foreach (Module module in moduleList)
            //{

            //    Console.WriteLine(module.ToString());
            //}

            #endregion

            #region 反射测试创建类型的对象  通过构造函数或者Activator的CreateInstance完成

            Type personType = assembly.GetType("反射测试的dll.Person");

            #region 1构造器创建类的实例

            ////用于获取带参数的构造器
            //ConstructorInfo constructor =
            //    personType.GetConstructor(new Type[] { typeof(string), typeof(int), typeof(string) });
            //var obj = constructor.Invoke(new object[] { "gzr", 24, "[email protected]" });

            //Console.WriteLine(obj.ToString());

            #endregion

            #region 2  系统激活器创建类的实例

            object obj = System.Activator.CreateInstance(personType);

            Console.WriteLine(obj.ToString());

            #endregion

            #region 类型方法句柄唯一及成员信息对象缓存机制测试

            //ConstructorInfo constructor1 =
            // personType.GetConstructor(new Type[] { typeof(string), typeof(int), typeof(string) });

            //由于类型对象在内存中只会有一份内存,也就意味着所有成员的句柄只会有一份,我们通过type的方法获取成员返回的是成员句柄的封装实例,此实例会被cl缓存下来

            //Console.WriteLine(constructor.MethodHandle.Value==constructor1.MethodHandle.Value);

            //Console.WriteLine(constructor==constructor1);

            ////用于获取不带参数的构造器
            //ConstructorInfo noparamConstructorInfo = personType.GetConstructor(new Type[] {});

            ////用于获取不带参数的构造器
            //ConstructorInfo noparamConstructorInfo1 = personType.GetConstructor(new Type[] { });

            #endregion

            #endregion

            #region 反射测试类型的属性

            PropertyInfo namPropertyInfo = personType.GetProperty("Name");

            Console.WriteLine(namPropertyInfo.GetValue(obj, null));

            #endregion

            #region 反射测试类型的索引器

            #endregion

            #region 反射测试类型的方法

            MethodInfo methodInfo = personType.GetMethod("SayHello");

            methodInfo.Invoke(obj, null);

//.........这里部分代码省略.........
开发者ID:junyong-tsui,项目名称:csharpexamples,代码行数:101,代码来源:Program.cs

示例10: Main

    static void Main()
    {
        Console.WriteLine();

             Point3D p1 = new Point3D(4,5,6);
             Point3D p2 = new Point3D(6,7,8);
             Console.Write("Distance between points: ");
             double temp = Calculate.Distance(p1, p2);
             Console.Write(temp);
             Console.WriteLine();

             Console.WriteLine();

             Path path = new Path();
             path.Add(p1);
             path.Add(p2);

             foreach (var item in path.Elements)
             {
                 Console.WriteLine(item);
             }

             PathStorage.Save(path);
             Path pathLoadExample = PathStorage.Load();

             Console.WriteLine();

             foreach (var item in pathLoadExample.Elements)
             {
                 Console.WriteLine("Loaded path: " + item.ToString());
             }

             GenericList<string> myList = new GenericList<string>(2);
             myList.Add("hop");
             myList.Add("trop");
             myList.Add("bau");

             Console.WriteLine();

             Console.WriteLine(myList.ToString());

             Console.WriteLine();

             string tempStr = myList.Min();
             Console.WriteLine("Minimum element -" + tempStr);

             Console.WriteLine();

             Object version = new Program();
             Console.Write("Version: ");
             Console.WriteLine(version.GetType().GetCustomAttributes(typeof(VersionAttribute), false)[0].ToString());

             Console.WriteLine();

        //     Matrix myMatrix = new Matrix(2, 3);
        //Matrix yourMatrix = new Matrix(3, 2);
        //Matrix result;

        //for (int i = 0; i < myMatrix.Rows; i++)
        //{
        //    for (int j = 0; j < myMatrix.Columns; j++)
        //    {
        //        myMatrix[i, j] = int.Parse(Console.ReadLine());
        //    }

        //}

        //for (int i = 0; i < yourMatrix.Rows; i++)
        //{
        //    for (int j = 0; j < yourMatrix.Columns; j++)
        //    {
        //        yourMatrix[i, j] = int.Parse(Console.ReadLine());
        //    }

        //}

        //Console.WriteLine();

        //result = myMatrix*yourMatrix;

        //for (int i = 0; i < yourMatrix.Rows; i++)
        //{
        //    for (int j = 0; j < yourMatrix.Columns; j++)
        //    {
        //        Console.Write(yourMatrix[i, j]);
        //    }
        //    Console.WriteLine();

        //}

        //for (int i = 0; i < result.Rows; i++)
        //{
        //    for (int j = 0; j < result.Columns; j++)
        //    {
        //        Console.Write(result[i, j]);
        //    }
        //    Console.WriteLine();

        //}

//.........这里部分代码省略.........
开发者ID:huuuskyyy,项目名称:CSharp-Homeworks,代码行数:101,代码来源:Test_Here.cs


注:本文中的Program.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。