本文整理汇总了C#中System.Type.GetMember方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetMember方法的具体用法?C# Type.GetMember怎么用?C# Type.GetMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetMember方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Security;
using System.Reflection;
public class MyMemberSample
{
public static void Main()
{
MyMemberSample myClass = new MyMemberSample();
try
{
myClass.GetMemberInfo();
myClass.GetPublicStaticMemberInfo();
myClass.GetPublicInstanceMethodMemberInfo();
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException occurred.");
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Message: " + e.Message);
}
catch(NotSupportedException e)
{
Console.WriteLine("NotSupportedException occurred.");
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Message: " + e.Message);
}
catch(SecurityException e)
{
Console.WriteLine("SecurityException occurred.");
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Message: " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception occurred.");
Console.WriteLine("Source: " + e.Source);
Console.WriteLine("Message: " + e.Message);
}
}
public void GetMemberInfo()
{
String myString = "GetMember_String";
Type myType = myString.GetType();
// Get the members for myString starting with the letter C.
MemberInfo[] myMembers = myType.GetMember("C*");
if(myMembers.Length > 0)
{
Console.WriteLine("\nThe member(s) starting with the letter C for type {0}:", myType);
for(int index=0; index < myMembers.Length; index++)
Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
}
else
{
Console.WriteLine("No members match the search criteria.");
}
}
示例2: GetPublicStaticMemberInfo
public void GetPublicStaticMemberInfo()
{
String myString = "GetMember_String_BindingFlag";
Type myType = myString.GetType();
// Get the public static members for the class myString starting with the letter C.
MemberInfo[] myMembers = myType.GetMember("C*",
BindingFlags.Public |BindingFlags.Static);
if(myMembers.Length > 0)
{
Console.WriteLine("\nThe public static member(s) starting with the letter C for type {0}:", myType);
for(int index=0; index < myMembers.Length; index++)
Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
}
else
{
Console.WriteLine("No members match the search criteria.");
}
}
示例3: GetPublicInstanceMethodMemberInfo
public void GetPublicInstanceMethodMemberInfo()
{
String myString = "GetMember_String_MemberType_BindingFlag";
Type myType = myString.GetType();
// Get the public instance methods for myString starting with the letter C.
MemberInfo[] myMembers = myType.GetMember("C*", MemberTypes.Method,
BindingFlags.Public | BindingFlags.Instance);
if(myMembers.Length > 0)
{
Console.WriteLine("\nThe public instance method(s) starting with the letter C for type {0}:", myType);
for(int index=0; index < myMembers.Length; index++)
Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
}
else
{
Console.WriteLine("No members match the search criteria.");
}
}
}