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


C# ITypeSymbol.DefiningType方法代码示例

本文整理汇总了C#中ITypeSymbol.DefiningType方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeSymbol.DefiningType方法的具体用法?C# ITypeSymbol.DefiningType怎么用?C# ITypeSymbol.DefiningType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITypeSymbol的用法示例。


在下文中一共展示了ITypeSymbol.DefiningType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryGetTypeReference

    public bool TryGetTypeReference(ITypeSymbol semanticType, IAssemblyReference cciAssembly, out ITypeReference cciType) {
      Contract.Ensures(!Contract.Result<bool>() || (Contract.ValueAtReturn(out cciType) != null));

      cciType = null;

      #region Check input
      if (semanticType == null || cciAssembly == null) {
        return false;
      }
      #endregion
      #region Check cache
      if (ContractsPackageAccessor.Current.VSOptionsPage.Caching)
        if (_semanticTypesToCCITypes.TryGetValue(semanticType, out cciType))
          return cciType != null && cciType != Dummy.TypeReference;
      #endregion
      #region If generic
      if (!semanticType.TypeArguments().IsDefault && semanticType.TypeArguments().Length > 0) {
        var genericArguments = new List<ITypeReference>();
        foreach (var semanticTypeArg in semanticType.TypeArguments()) {
          if (semanticTypeArg == null) goto ReturnFalse;
          ITypeReference cciTypeArg = null;
          if (TryGetTypeReference(semanticTypeArg, out cciTypeArg)) {
            genericArguments.Add(cciTypeArg);
          } else {
            goto ReturnFalse;
          }
        }
        ITypeReference genericType = null;
        if (!TryGetTypeReference(semanticType.DefiningType(), out genericType)) {
          goto ReturnFalse;
        }
        cciType = new Microsoft.Cci.MutableCodeModel.GenericTypeInstanceReference() {
          InternFactory = this.Host.InternFactory,
          GenericArguments = genericArguments,
          GenericType = (INamedTypeReference) genericType,
        };
        goto ReturnTrue;
      }
      #endregion
      #region If array
      if (semanticType.TypeKind == TypeKind.Array) {
        ITypeReference eleType;
        if (!TryGetTypeReference(semanticType.ElementType(), out eleType))
          goto ReturnFalse;
        if (semanticType.ElementType().TypeKind == TypeKind.Array) {
          Contract.Assume(((IArrayTypeSymbol)semanticType).Rank > 0);
          cciType = new Microsoft.Cci.MutableCodeModel.MatrixTypeReference() {
            ElementType = eleType,
            InternFactory = this.Host.InternFactory,
            Rank = (uint)((IArrayTypeSymbol)semanticType).Rank
          };
          goto ReturnTrue;
        } else {
          cciType = new Microsoft.Cci.MutableCodeModel.VectorTypeReference() {
            ElementType = eleType,
            InternFactory = this.Host.InternFactory,
          };
          goto ReturnTrue;
        }
      }
      #endregion
      #region If type parameter
      if (semanticType.TypeKind == TypeKind.TypeParameter) {
        if (semanticType.DefiningMember() != null) {
          cciType = new Microsoft.Cci.MutableCodeModel.GenericMethodParameterReference() {
            Index = (ushort)(!semanticType.DefiningMember().TypeParameters().IsDefault ? semanticType.DefiningMember().TypeParameters().IndexOf((ITypeParameterSymbol)semanticType) : 0),
            InternFactory = this.Host.InternFactory,
            Name = Host.NameTable.GetNameFor(semanticType.Name != null ? semanticType.Name : "T"),
          };
          goto ReturnTrue;
        } else if (semanticType.DefiningType() != null) {
          ITypeReference cciDefiningType;
          if (!TryGetTypeReference(semanticType.DefiningType(), out cciDefiningType))
            goto ReturnFalse;
          cciType = new Microsoft.Cci.MutableCodeModel.GenericTypeParameterReference() {
            DefiningType = cciDefiningType,
            Index = (ushort)(!semanticType.DefiningType().TypeParameters().IsDefaultOrEmpty ? semanticType.DefiningType().TypeParameters().IndexOf((ITypeParameterSymbol)semanticType) : 0),
            InternFactory = this.Host.InternFactory,
            Name = Host.NameTable.GetNameFor(semanticType.Name != null ? semanticType.Name : "T"),
          };
          goto ReturnTrue;
        }
      }
      #endregion
      #region If namespace type
      if (semanticType.ContainingType == null)
      {
        IUnitNamespaceReference cciNamespace;
        var namespaceName = semanticType.ContainingNamespace;
        if (namespaceName == null || !TryGetNamespaceReference(namespaceName, cciAssembly, out cciNamespace))
        {
          cciNamespace = new Microsoft.Cci.MutableCodeModel.RootUnitNamespaceReference() { Unit = cciAssembly };
        }
        if (semanticType.ContainingType == null)
        {
          if (semanticType.Name == null || semanticType.Name == null) goto ReturnFalse;
          cciType = new Microsoft.Cci.MutableCodeModel.NamespaceTypeReference()
          {
            ContainingUnitNamespace = cciNamespace,
            GenericParameterCount = (ushort) (semanticType.TypeParameters().IsDefault ? 0 : semanticType.TypeParameters().Length),
//.........这里部分代码省略.........
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:101,代码来源:ContractsProvider.cs


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