本文整理汇总了C#中System.Reflection.TypeInfo.GetInterfaces方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.GetInterfaces方法的具体用法?C# TypeInfo.GetInterfaces怎么用?C# TypeInfo.GetInterfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.GetInterfaces方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatType
IEnumerable<string> FormatType(TypeInfo type)
{
if (type.IsEnum)
{
return $"{type.Name}".InArray()
.Concat("{")
.Concat(Enum.GetValues(type.AsType()).Cast<Enum>().Select(v => $" {v} = {(int)(object)v}"))
.Concat("}");
}
var kind = type.IsInterface
? "interface"
: type.IsAbstract
? "abstract class"
: "class";
var interfaces = type.GetInterfaces();
var members = type.GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public)
.OrderBy(t => t.Name)
.ToArray();
var fields = members.OfType<FieldInfo>().ToArray();
var ctors = members.OfType<ConstructorInfo>().ToArray();
var properties = members.OfType<PropertyInfo>().ToArray();
var events = members.OfType<EventInfo>().ToArray();
var methods = members.OfType<MethodInfo>().ToArray();
var types = members.OfType<TypeInfo>().ToArray();
var other = members.Except(methods).Except(properties).Except(fields).Except(ctors).Except(events).Except(types).ToArray();
var body = fields.Select(f => $"{Static(f.IsStatic)}{f.FieldType} {f.Name}")
.Concat(events.Select(e => $"event {FormatTypeName(e.EventHandlerType)} {e.Name}"))
.Concat(ctors.SelectMany(FormatCtor))
.Concat(properties.Select(p => $"{FormatProperty(p)}"))
.Concat(methods.SelectMany(FormatMethods))
.Concat(other.Select(o => $"UNKNOWN {o.GetType().Name} {o.Name}"))
.Concat(types.SelectMany(FormatType));
return
$"{kind} {type.Name}".InArray()
.Concat(interfaces.Select(i => $" {FormatTypeName(i)}"))
.Concat("{")
.Concat(body.Select(l => " " + l))
.Concat("}");
}
示例2: ConsiderGenericInterfacesArguments
private static void ConsiderGenericInterfacesArguments(
TypeInfo typeInfo,
Module module,
Assembly targetAssembly,
ISet<Type> includedTypes)
{
var interfaces = typeInfo.GetInterfaces().Where(x =>
x.IsConstructedGenericType
&& SerializerGenerationManager.KnownGenericIntefaceTypes.Contains(x.GetGenericTypeDefinition()));
foreach (var type in interfaces.SelectMany(v => v.GetGenericArguments()))
{
RecordType(type, module, targetAssembly, includedTypes);
}
}
示例3: ConsiderGenericInterfacesArguments
private static void ConsiderGenericInterfacesArguments(
TypeInfo typeInfo,
Module module,
Assembly targetAssembly,
ISet<Type> includedTypes)
{
var interfaces = typeInfo.GetInterfaces().Where(x => x.IsConstructedGenericType);
foreach (var type in interfaces.SelectMany(v => v.GetTypeInfo().GetGenericArguments()))
{
RecordType(type, module, targetAssembly, includedTypes);
}
}