Exemple #1
0
        internal static INamespaceTypeReference CreateTypeReference(IMetadataHost host, IAssemblyReference assemblyReference, string typeName, ushort genericParameterCount)
        {
            IUnitNamespaceReference ns = new Microsoft.Cci.Immutable.RootUnitNamespaceReference(assemblyReference);

            string[] names = typeName.Split('.');
            for (int i = 0, n = names.Length - 1; i < n; i++)
            {
                ns = new Microsoft.Cci.Immutable.NestedUnitNamespaceReference(ns, host.NameTable.GetNameFor(names[i]));
            }
            return(new Microsoft.Cci.Immutable.NamespaceTypeReference(host, ns, host.NameTable.GetNameFor(names[names.Length - 1]), genericParameterCount, false, false, true, PrimitiveTypeCode.NotPrimitive));
        }
Exemple #2
0
        private static INamespaceTypeReference CreateTypeReference(IMetadataHost host, IAssemblyReference assemblyReference, string typeName, bool isValueType = false, bool isEnum = false)
        {
            IUnitNamespaceReference ns = new Microsoft.Cci.Immutable.RootUnitNamespaceReference(assemblyReference);
            var names = typeName.Split('.');

            for (int i = 0, n = names.Length - 1; i < n; ++i)
            {
                ns = new Microsoft.Cci.Immutable.NestedUnitNamespaceReference(ns, host.NameTable.GetNameFor(names[i]));
            }

            return(new Microsoft.Cci.Immutable.NamespaceTypeReference(host, ns, host.NameTable.GetNameFor(names[names.Length - 1]), 0, isEnum: isEnum, isValueType: isValueType));
        }
    public bool TryGetNamespaceReference(INamespaceSymbol semanticNamespace, IAssemblyReference cciAssembly, out IUnitNamespaceReference cciNamespace) {
      Contract.Ensures(!Contract.Result<bool>() || (Contract.ValueAtReturn(out cciNamespace) != null));

      cciNamespace = null;

      #region Check input
      if (semanticNamespace == null || cciAssembly == null) {
        return false;
      }
      #endregion
      #region If root
      try {
        if (semanticNamespace.IsGlobalNamespace) {
          cciNamespace = new Microsoft.Cci.MutableCodeModel.RootUnitNamespaceReference() { Unit = cciAssembly };
          goto ReturnTrue;
        }
      } catch (InvalidOperationException e) { //For some reason, an InvalidOperationException may get thrown.
        if (e.Message.Contains(ContractsPackageAccessor.InvalidOperationExceptionMessage_TheSnapshotIsOutOfDate))
          goto ReturnFalse;
        else
          throw e;
      }
      #endregion
      #region If nested
      if (semanticNamespace.ContainingNamespace != null) {
        IUnitNamespaceReference parentNs;
        if (!TryGetNamespaceReference(semanticNamespace.ContainingNamespace, cciAssembly, out parentNs))
          goto ReturnFalse;
        if (semanticNamespace.Name == null) goto ReturnFalse;
        cciNamespace = new Microsoft.Cci.Immutable.NestedUnitNamespaceReference(parentNs, Host.NameTable.GetNameFor(semanticNamespace.Name));
        goto ReturnTrue;
      }
      #endregion
      Contract.Assert(cciNamespace == null);
      goto ReturnFalse;

      #region ReturnTrue:
    ReturnTrue:
      return true;
      #endregion
      #region ReturnFalse:
    ReturnFalse:
      return false;
      #endregion
    }
Exemple #4
0
        public bool TryGetNamespaceReference(CSharpNamespace semanticNamespace, IAssemblyReference cciAssembly, out IUnitNamespaceReference cciNamespace)
        {
            Contract.Ensures(!Contract.Result <bool>() || (Contract.ValueAtReturn(out cciNamespace) != null));

            cciNamespace = null;

            #region Check input
            if (semanticNamespace == null || cciAssembly == null)
            {
                return(false);
            }
            #endregion
            #region If root
            try {
                if (semanticNamespace.IsRoot)
                {
                    cciNamespace = new Microsoft.Cci.MutableCodeModel.RootUnitNamespaceReference()
                    {
                        Unit = cciAssembly
                    };
                    goto ReturnTrue;
                }
            } catch (InvalidOperationException e) { //For some reason, an InvalidOperationException may get thrown.
                if (e.Message.Contains(ContractsPackageAccessor.InvalidOperationExceptionMessage_TheSnapshotIsOutOfDate))
                {
                    goto ReturnFalse;
                }
                else
                {
                    throw e;
                }
            }
            #endregion
            #region If nested
            if (semanticNamespace.ContainingNamespace != null)
            {
                IUnitNamespaceReference parentNs;
                if (!TryGetNamespaceReference(semanticNamespace.ContainingNamespace, cciAssembly, out parentNs))
                {
                    goto ReturnFalse;
                }
                if (semanticNamespace.Name == null)
                {
                    goto ReturnFalse;
                }
                cciNamespace = new Microsoft.Cci.Immutable.NestedUnitNamespaceReference(parentNs, Host.NameTable.GetNameFor(semanticNamespace.Name.Text));
                goto ReturnTrue;
            }
            #endregion
            Contract.Assert(cciNamespace == null);
            goto ReturnFalse;

            #region ReturnTrue:
ReturnTrue:
            return(true);

            #endregion
            #region ReturnFalse:
ReturnFalse:
            return(false);

            #endregion
        }