private TypeWithAnnotations GetConstraintTypeOrDefault(PEModuleSymbol moduleSymbol, MetadataReader metadataReader, MetadataDecoder tokenDecoder, GenericParameterConstraintHandle constraintHandle, ref bool hasUnmanagedModreqPattern)
        {
            var constraint = metadataReader.GetGenericParameterConstraint(constraintHandle);
            var typeSymbol = tokenDecoder.DecodeGenericParameterConstraint(constraint.Type, out ImmutableArray <ModifierInfo <TypeSymbol> > modifiers);

            if (!modifiers.IsDefaultOrEmpty && modifiers.Length > 1)
            {
                typeSymbol = new UnsupportedMetadataTypeSymbol();
            }
            else if (typeSymbol.SpecialType == SpecialType.System_ValueType)
            {
                // recognize "(class [mscorlib]System.ValueType modreq([mscorlib]System.Runtime.InteropServices.UnmanagedType" pattern as "unmanaged"
                if (!modifiers.IsDefaultOrEmpty)
                {
                    ModifierInfo <TypeSymbol> m = modifiers.Single();
                    if (!m.IsOptional && m.Modifier.IsWellKnownTypeUnmanagedType())
                    {
                        hasUnmanagedModreqPattern = true;
                    }
                    else
                    {
                        // Any other modifiers, optional or not, are not allowed: http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/528856
                        typeSymbol = new UnsupportedMetadataTypeSymbol();
                    }
                }

                // Drop 'System.ValueType' constraint type if the 'valuetype' constraint was also specified.
                if (typeSymbol.SpecialType == SpecialType.System_ValueType && ((_flags & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0))
                {
                    return(default);
Example #2
0
 public GenericParamConstraintEntry(PEFile module, GenericParameterConstraintHandle handle)
 {
     this.metadataOffset         = module.Reader.PEHeaders.MetadataStartOffset;
     this.module                 = module;
     this.metadata               = module.Metadata;
     this.handle                 = handle;
     this.genericParamConstraint = metadata.GetGenericParameterConstraint(handle);
     this.ownerTooltip           = null;
 }
Example #3
0
 public override Type[] GetGenericParameterConstraints()
 {
     return
         (Definition
          .GetConstraints()
          .Select(
              handle => MetadataDomain.GetMetadataType(
                  _metadata,
                  _metadata.GetGenericParameterConstraint(handle).Type))
          .ToArray());
 }
Example #4
0
 static bool FindUsesInGenericConstraints(MetadataReader metadata, GenericParameterHandleCollection collection, FindTypeDecoder decoder)
 {
     foreach (var h in collection)
     {
         var gp = metadata.GetGenericParameter(h);
         foreach (var hc in gp.GetConstraints())
         {
             var gc = metadata.GetGenericParameterConstraint(hc);
             if (decoder.GetTypeFromEntity(metadata, gc.Type))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        private TypeWithAnnotations GetConstraintTypeOrDefault(PEModuleSymbol moduleSymbol, MetadataReader metadataReader, MetadataDecoder tokenDecoder, GenericParameterConstraintHandle constraintHandle, ref bool hasUnmanagedModreqPattern)
        {
            var constraint = metadataReader.GetGenericParameterConstraint(constraintHandle);
            var typeSymbol = tokenDecoder.DecodeGenericParameterConstraint(constraint.Type, out bool hasUnmanagedModreq);

            if (typeSymbol.SpecialType == SpecialType.System_ValueType)
            {
                // recognize "(class [mscorlib]System.ValueType modreq([mscorlib]System.Runtime.InteropServices.UnmanagedType" pattern as "unmanaged"
                if (hasUnmanagedModreq)
                {
                    hasUnmanagedModreqPattern = true;
                }

                // Drop 'System.ValueType' constraint type if the 'valuetype' constraint was also specified.
                if (((_flags & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0))
                {
                    return(default);
        private void WriteGenericParamConstraint()
        {
            AddHeader(
                "Parent",
                "Type"
                );

            for (int i = 1, count = reader.GetTableRowCount(TableIndex.GenericParamConstraint); i <= count; i++)
            {
                var entry = reader.GetGenericParameterConstraint(MetadataTokens.GenericParameterConstraintHandle(i));

                AddRow(
                    Token(entry.Parameter),
                    Token(entry.Type)
                    );
            }

            WriteRows("GenericParamConstraint (0x2c):");
        }
Example #7
0
 public static string ToString(this MetadataReader reader, GenericParameterConstraintHandle x) => reader.ToString(reader.GetGenericParameterConstraint(x));
Example #8
0
 public static GenericParameterConstraint GetGenericParameterConstraint(this GenericParameterConstraintHandle handle, MetadataReader reader) => reader.GetGenericParameterConstraint(handle);