本文整理汇总了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);
}
}
}