本文整理匯總了C#中System.Type.GetInterfaces方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.GetInterfaces方法的具體用法?C# Type.GetInterfaces怎麽用?C# Type.GetInterfaces使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Type
的用法示例。
在下文中一共展示了Type.GetInterfaces方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Collections.Generic;
public class Example
{
static void Main()
{
Console.WriteLine("\r\nInterfaces implemented by Dictionary<int, string>:\r\n");
foreach (Type tinterface in typeof(Dictionary<int, string>).GetInterfaces())
{
Console.WriteLine(tinterface.ToString());
}
//Console.ReadLine() // Uncomment this line for Visual Studio.
}
}
輸出:
Interfaces implemented by Dictionary: System.Collections.Generic.IDictionary`2[System.Int32,System.String] System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]] System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]] System.Collection.IEnumerable System.Collection.IDictionary System.Collection.ICollection System.Runtime.Serialization.ISerializable System.Runtime.Serialization.IDeserializationCallback
示例2: Type.GetInterfaces()
//引入命名空間
using System;
using System.Reflection;
class MainClass {
public static void ShowInterfaces(Type t) {
Type[] interfaces = t.GetInterfaces();
Console.WriteLine("Implemented Interfaces");
foreach (Type type in interfaces) {
Console.WriteLine("Interface : {0}", type.FullName);
if (type.IsPublic)
Console.WriteLine("Scope: Public");
else
Console.WriteLine("Scope: Private");
}
}
public static void ShowTypes(string name, Assembly assembly) {
Type[] typeArray = assembly.GetTypes();
Console.WriteLine("Assembly Name: {0}", name);
foreach (Type type in typeArray) {
if (type.IsClass) {
ShowInterfaces(type);
}
}
}
public static void Main(string[] args) {
for (int i = 0; i < args.Length; ++i) {
// Get the assemble object (from System.Reflection)
Assembly assembly = Assembly.LoadFrom(args[0]);
ShowTypes(args[0], assembly);
}
}
}