本文整理汇总了C#中System.Type.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetType方法的具体用法?C# Type.GetType怎么用?C# Type.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
class Example
{
public static void Main()
{
try {
// Get the type of a specified class.
Type myType1 = Type.GetType("System.Int32");
Console.WriteLine("The full name is {0}.\n", myType1.FullName);
}
catch (TypeLoadException e)
{
Console.WriteLine("{0}: Unable to load type System.Int32", e.GetType().Name);
}
try {
// Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException.
Type myType2 = Type.GetType("NoneSuch", true);
Console.WriteLine("The full name is {0}.", myType2.FullName);
}
catch(TypeLoadException e) {
Console.WriteLine("{0}: Unable to load type NoneSuch", e.GetType().Name);
}
}
}
输出:
The full name is System.Int32. TypeLoadException: Unable to load type NoneSuch
示例2:
Type t2 = Type.GetType(test,
(aName) => aName.Name == "MyAssembly" ?
Assembly.LoadFrom(@".\MyPath\v5.0\MyAssembly.dll") :
Assembly.Load(aName),
(assem, name, ignore) => assem == null ?
Type.GetType(name, false, ignore) :
assem.GetType(name, false, ignore), true
);
示例3: Type.GetType(String typeName)
//引入命名空间
using System;
using System.Text;
class MainClass
{
public static void Main()
{
Type t2 = Type.GetType("System.String");
}
}
示例4:
Type t = Type.GetType(test,
(aName) => aName.Name == "MyAssembly" ?
Assembly.LoadFrom(@".\MyPath\v5.0\MyAssembly.dll") : null,
(assem, name, ignore) => assem == null ?
Type.GetType(name, false, ignore) :
assem.GetType(name, false, ignore)
);
示例5: Type.GetType(String typeName, true)
//引入命名空间
using System;
using System.Text;
class MainClass
{
public static void Main()
{
Type t3 = Type.GetType("System.String", true);
}
}
示例6: Type.GetType(String typeName, true, true);
//引入命名空间
using System;
using System.Text;
class MainClass
{
public static void Main()
{
Type t4 = Type.GetType("system.string", true, true);
}
}