mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection.Metadata;
|
|
|
|
namespace Semmle.Extraction.CIL.Entities
|
|
{
|
|
internal static class GenericsHelper
|
|
{
|
|
public static TypeTypeParameter[] MakeTypeParameters(Type container, int count)
|
|
{
|
|
var newTypeParams = new TypeTypeParameter[count];
|
|
for (var i = 0; i < newTypeParams.Length; ++i)
|
|
{
|
|
newTypeParams[i] = new TypeTypeParameter(container, i);
|
|
}
|
|
return newTypeParams;
|
|
}
|
|
|
|
public static string GetNonGenericName(StringHandle name, MetadataReader reader)
|
|
{
|
|
var n = reader.GetString(name);
|
|
return GetNonGenericName(n);
|
|
}
|
|
|
|
public static string GetNonGenericName(string name)
|
|
{
|
|
var tick = name.LastIndexOf('`');
|
|
return tick == -1
|
|
? name
|
|
: name.Substring(0, tick);
|
|
}
|
|
|
|
public static int GetGenericTypeParameterCount(StringHandle name, MetadataReader reader)
|
|
{
|
|
var n = reader.GetString(name);
|
|
return GetGenericTypeParameterCount(n);
|
|
}
|
|
|
|
public static int GetGenericTypeParameterCount(string name)
|
|
{
|
|
var tick = name.LastIndexOf('`');
|
|
return tick == -1
|
|
? 0
|
|
: int.Parse(name.Substring(tick + 1));
|
|
}
|
|
|
|
public static IEnumerable<Type> GetAllTypeParameters(Type? container, IEnumerable<TypeTypeParameter> thisTypeParameters)
|
|
{
|
|
if (container is not null)
|
|
{
|
|
foreach (var t in container.TypeParameters)
|
|
yield return t;
|
|
}
|
|
|
|
foreach (var t in thisTypeParameters)
|
|
yield return t;
|
|
|
|
}
|
|
}
|
|
}
|