本文整理汇总了C#中ITypeInfo.GetGenericArguments方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeInfo.GetGenericArguments方法的具体用法?C# ITypeInfo.GetGenericArguments怎么用?C# ITypeInfo.GetGenericArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeInfo
的用法示例。
在下文中一共展示了ITypeInfo.GetGenericArguments方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeFromGenericArgumentReferenceType
private static ITypeInfo GetTypeFromGenericArgumentReferenceType(IMetadataGenericArgumentReferenceType reference, ITypeInfo typeInfo, IMethodInfo methodInfo)
{
var argument = reference.Argument;
switch (argument.Kind)
{
case GenericArgumentKind.Type:
return typeInfo.GetGenericArguments().ToList()[(int)argument.Index];
case GenericArgumentKind.Method:
return methodInfo.GetGenericArguments().ToList()[(int)argument.Index];
}
return null;
}
示例2: ConvertToSimpleTypeName
static string ConvertToSimpleTypeName(ITypeInfo type)
{
var baseTypeName = type.Name;
var backTickIdx = baseTypeName.IndexOf('`');
if (backTickIdx >= 0)
baseTypeName = baseTypeName.Substring(0, backTickIdx);
var lastIndex = baseTypeName.LastIndexOf('.');
if (lastIndex >= 0)
baseTypeName = baseTypeName.Substring(lastIndex + 1);
if (!type.IsGenericType)
return baseTypeName;
var genericTypes = type.GetGenericArguments().ToArray();
var simpleNames = new string[genericTypes.Length];
for (var idx = 0; idx < genericTypes.Length; idx++)
simpleNames[idx] = ConvertToSimpleTypeName(genericTypes[idx]);
return $"{baseTypeName}<{string.Join(", ", simpleNames)}>";
}
示例3: ConvertToSimpleTypeName
static string ConvertToSimpleTypeName(ITypeInfo type)
{
var baseTypeName = type.Name;
int backTickIdx = baseTypeName.IndexOf('`');
if (backTickIdx >= 0)
baseTypeName = baseTypeName.Substring(0, backTickIdx);
var lastIndex = baseTypeName.LastIndexOf('.');
if (lastIndex >= 0)
baseTypeName = baseTypeName.Substring(lastIndex + 1);
if (!type.IsGenericType)
return baseTypeName;
ITypeInfo[] genericTypes = type.GetGenericArguments().ToArray();
string[] simpleNames = new string[genericTypes.Length];
for (int idx = 0; idx < genericTypes.Length; idx++)
simpleNames[idx] = ConvertToSimpleTypeName(genericTypes[idx]);
return String.Format("{0}<{1}>", baseTypeName, String.Join(", ", simpleNames));
}