本文整理汇总了C#中System.Reflection.ParameterInfo.ParameterType属性的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.ParameterType属性的具体用法?C# ParameterInfo.ParameterType怎么用?C# ParameterInfo.ParameterType使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.ParameterType属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: mymethod
//引入命名空间
using System;
using System.Reflection;
class parminfo
{
public static void mymethod (
int int1m, out string str2m, ref string str3m)
{
str2m = "in mymethod";
}
public static int Main(string[] args)
{
Console.WriteLine("\nReflection.Parameterinfo");
//Get the ParameterInfo parameter of a function.
//Get the type.
Type Mytype = Type.GetType("parminfo");
//Get and display the method.
MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
Console.Write("\nMymethodbase = " + Mymethodbase);
//Get the ParameterInfo array.
ParameterInfo[]Myarray = Mymethodbase.GetParameters();
//Get and display the ParameterInfo of each parameter.
foreach (ParameterInfo Myparam in Myarray)
{
Console.Write ("\nFor parameter # " + Myparam.Position
+ ", the ParameterType is - " + Myparam.ParameterType);
}
return 0;
}
}
输出:
Reflection.Parameterinfo Mymethodbase = Void mymethod(Int32, System.String ByRef, System.String ByRef) For parameter # 0, the ParameterType is - System.Int32 For parameter # 1, the ParameterType is - System.String& For parameter # 2, the ParameterType is - System.String&
示例2: MyClass
//引入命名空间
using System;
using System.Reflection;
class MyClass {
public MyClass(int i, int j) {
}
public int sum() {
return 0;
}
public bool isBetween(int i) {
return false;
}
public void set(int a, int b) {
}
public void set(double a, double b) {
}
public void show() {
Console.WriteLine("show");
}
}
class MainClass {
public static void Main() {
Type t = typeof(MyClass);
Console.WriteLine("Analyzing methods in " + t.Name);
Console.WriteLine();
Console.WriteLine("Methods supported: ");
MethodInfo[] mi = t.GetMethods();
// Display methods supported by MyClass.
foreach(MethodInfo m in mi) {
// Display return type and name.
Console.Write(" " + m.ReturnType.Name +
" " + m.Name + "(");
// Display parameters.
ParameterInfo[] pi = m.GetParameters();
for(int i=0; i < pi.Length; i++) {
Console.Write(pi[i].ParameterType.Name +
" " + pi[i].Name);
if(i+1 < pi.Length) Console.Write(", ");
}
Console.WriteLine(")");
Console.WriteLine();
}
}
}