当前位置: 首页>>代码示例>>C#>>正文


C# TypeNode.GetGenericTemplateInstance方法代码示例

本文整理汇总了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;
 }
开发者ID:julianhaslinger,项目名称:SHFB,代码行数:74,代码来源:Reader.cs


注:本文中的TypeNode.GetGenericTemplateInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。