本文整理匯總了C#中System.Reflection.Assembly.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# Assembly.GetType方法的具體用法?C# Assembly.GetType怎麽用?C# Assembly.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Reflection;
public class Example
{
public static void Main()
{
Assembly assem = typeof(Example).Assembly;
Type t = assem.GetType("Transportation.MeansOfTransportation");
if (t != null)
{
Console.WriteLine($"Virtual properties in type {t.FullName}:");
PropertyInfo[] props = t.GetProperties();
int nVirtual = 0;
for (int ctr = 0; ctr < props.Length; ctr++)
{
if (props[ctr].GetMethod.IsVirtual)
{
Console.WriteLine($" {props[ctr].Name} (type {props[ctr].PropertyType.FullName})");
nVirtual++;
}
}
if (nVirtual == 0)
Console.WriteLine(" No virtual properties");
}
}
}
namespace Transportation
{
public abstract class MeansOfTransportation
{
abstract public bool HasWheels { get; set; }
abstract public int Wheels { get; set; }
abstract public bool ConsumesFuel { get; set; }
abstract public bool Living { get; set; }
}
}
輸出:
Virtual properties in type Transportation.MeansOfTransportation: HasWheels (type System.Boolean) Wheels (type System.Int32) ConsumesFuel (type System.Boolean) Living (type System.Boolean)