本文整理汇总了C#中TypeNode.GetGenericTemplateInstance方法的典型用法代码示例。如果您正苦于以下问题:C# TypeNode.GetGenericTemplateInstance方法的具体用法?C# TypeNode.GetGenericTemplateInstance怎么用?C# TypeNode.GetGenericTemplateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeNode
的用法示例。
在下文中一共展示了TypeNode.GetGenericTemplateInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseArrayOrGenericType
private TypeNode/*!*/ ParseArrayOrGenericType(string typeName, TypeNode/*!*/ rootType)
{
if (typeName == null || rootType == null) { Debug.Assert(false); return rootType; }
//Get here after "rootType[" has been parsed. What follows is either an array type specifier or some generic type arguments.
if (typeName.Length == 0)
throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName); //Something ought to follow the [
if (typeName[0] == ']')
{ //Single dimensional array with zero lower bound
if (typeName.Length == 1) return rootType.GetArrayType(1);
if (typeName[1] == '[' && typeName.Length > 2)
return this.ParseArrayOrGenericType(typeName.Substring(2), rootType.GetArrayType(1));
throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName);
}
if (typeName[0] == '*')
{ //Single dimensional array with unknown lower bound
if (typeName.Length > 1 && typeName[1] == ']')
{
if (typeName.Length == 2) return rootType.GetArrayType(1, true);
if (typeName[2] == '[' && typeName.Length > 3)
return this.ParseArrayOrGenericType(typeName.Substring(3), rootType.GetArrayType(1, true));
}
throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName);
}
if (typeName[0] == ',')
{ //Muti dimensional array
int rank = 1;
while (rank < typeName.Length && typeName[rank] == ',') rank++;
if (rank < typeName.Length && typeName[rank] == ']')
{
if (typeName.Length == rank + 1) return rootType.GetArrayType(rank + 1);
if (typeName[rank + 1] == '[' && typeName.Length > rank + 2)
return this.ParseArrayOrGenericType(typeName.Substring(rank + 2), rootType.GetArrayType(rank));
}
throw new InvalidMetadataException(ExceptionStrings.BadSerializedTypeName);
}
//Generic type instance
int offset = 0;
if (typeName[0] == '[') offset = 1; //Assembly qualified type name forming part of a generic parameter list
TypeNodeList arguments = new TypeNodeList();
int commaPos = FindFirstCommaOutsideBrackets(typeName);
while (commaPos > 1)
{
arguments.Add(this.GetTypeFromSerializedName(typeName.Substring(offset, commaPos - offset)));
typeName = typeName.Substring(commaPos + 1);
offset = typeName[0] == '[' ? 1 : 0;
commaPos = FindFirstCommaOutsideBrackets(typeName);
}
//Find the position of the first unbalanced ].
int lastCharPos = offset;
for (int leftBracketCount = 0; lastCharPos < typeName.Length; lastCharPos++)
{
char ch = typeName[lastCharPos];
if (ch == '[') leftBracketCount++;
else if (ch == ']')
{
leftBracketCount--;
if (leftBracketCount < 0) break;
}
}
arguments.Add(this.GetTypeFromSerializedName(typeName.Substring(offset, lastCharPos - offset)));
TypeNode retVal = rootType.GetGenericTemplateInstance(this.module, arguments);
if (lastCharPos + 1 < typeName.Length && typeName[lastCharPos + 1] == ']')
lastCharPos++;
if (lastCharPos + 1 < typeName.Length)
{
//The generic type is complete, but there is yet more to the type
char ch = typeName[lastCharPos + 1];
if (ch == '+') retVal = this.GetTypeFromSerializedName(typeName.Substring(lastCharPos + 2), retVal);
if (ch == '&') retVal = retVal.GetReferenceType();
if (ch == '*') retVal = retVal.GetPointerType();
if (ch == '[') retVal = this.ParseArrayOrGenericType(typeName.Substring(lastCharPos + 2, typeName.Length - 1 - lastCharPos - 1), retVal);
}
return retVal;
}