Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 public void CopyTypeReferences(Collection <GenericParameterConstraint> input, Collection <GenericParameterConstraint> output, IGenericParameterProvider context)
 {
     foreach (var gpc in input)
     {
         var result = new GenericParameterConstraint(Import(gpc.ConstraintType, context));
         CopyCustomAttributes(gpc.CustomAttributes, result.CustomAttributes, context);
         output.Add(result);
     }
 }
Ejemplo n.º 3
0
 public static AssemblyDefinition GetAssemblyFromCustomAttributeProvider(ICustomAttributeProvider provider)
 {
     return(provider switch {
         MemberReference mr => mr.Module.Assembly,
         AssemblyDefinition ad => ad,
         ModuleDefinition md => md.Assembly,
         InterfaceImplementation ii => ii.InterfaceType.Module.Assembly,
         GenericParameterConstraint gpc => gpc.ConstraintType.Module.Assembly,
         ParameterDefinition pd => pd.ParameterType.Module.Assembly,
         MethodReturnType mrt => mrt.ReturnType.Module.Assembly,
         _ => throw new NotImplementedException(provider.GetType().ToString()),
     });
Ejemplo n.º 4
0
        public bool Equals(GenericParameterConstraint x, GenericParameterConstraint y)
        {
            if (x == null && y == null)
            {
                return(true);
            }
            if (x == null || y == null)
            {
                return(false);
            }

            return(Equals(x.Constraint, y.Constraint));
        }
Ejemplo n.º 5
0
        public static GenericParameterConstraint Clone(this GenericParameterConstraint constraint, GenericParameter parameter, TypeDefinition typeDefinition)
        {
            var newConstraint =
                new GenericParameterConstraint(ImportGeneric(typeDefinition.Module, constraint.ConstraintType,
                                                             typeDefinition));

            parameter.Constraints.Add(newConstraint);
            foreach (var ca in constraint.CustomAttributes)
            {
                newConstraint.CustomAttributes.Add(ca.Clone(parameter.Module, constraint.ConstraintType.Module));
            }
            return(newConstraint);
        }
Ejemplo n.º 6
0
        private void AddGenericParameterConstraint(GenericParameterConstraint constraint)
        {
            var table = (GenericParameterConstraintTable)_tableStream.GetTable(MetadataTokenType.GenericParamConstraint);

            // Create and add row.
            var constraintRow = new MetadataRow <uint, uint>
            {
                Column1 = GetNewToken(constraint.Owner).Rid,
                Column2 = _tableStream.GetIndexEncoder(CodedIndex.TypeDefOrRef)
                          .EncodeToken(GetTypeToken(constraint.Constraint))
            };

            table.Add(constraintRow);
            _members.Add(constraint, constraintRow.MetadataToken);
        }
Ejemplo n.º 7
0
        public void FixPlatformVersion(GenericParameterConstraint constraint)
        {
            if (constraint == null)
            {
                return;
            }

            FixPlatformVersion(constraint.ConstraintType);
            if (constraint.HasCustomAttributes)
            {
                foreach (CustomAttribute ca in constraint.CustomAttributes)
                {
                    FixPlatformVersion(ca);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Relink the given type reference.
        /// </summary>
        /// <param name="constraint">The reference to relink.</param>
        /// <param name="relinker">The relinker to use during the relinking process.</param>
        /// <param name="context">The generic context provided to relink generic references.</param>
        /// <returns>A relinked reference.</returns>
        public static GenericParameterConstraint Relink(this GenericParameterConstraint constraint, Relinker relinker, IGenericParameterProvider context)
        {
            if (constraint == null)
            {
                return(null);
            }

            GenericParameterConstraint relink = new GenericParameterConstraint(constraint.ConstraintType.Relink(relinker, context));

            foreach (CustomAttribute attrib in constraint.CustomAttributes)
            {
                relink.CustomAttributes.Add(attrib.Relink(relinker, context));
            }

            return(relink);
        }
        private void AddGenericParameterConstraint(MetadataToken ownerToken,
                                                   GenericParameterConstraint constraint)
        {
            if (constraint is null)
            {
                return;
            }

            var table = Metadata.TablesStream.GetTable <GenericParameterConstraintRow>(TableIndex.GenericParamConstraint);

            var row = new GenericParameterConstraintRow(
                ownerToken.Rid,
                GetTypeDefOrRefIndex(constraint.Constraint));

            var token = table.Add(row);

            AddCustomAttributes(token, constraint);
        }
Ejemplo n.º 10
0
 public int GetHashCode(GenericParameterConstraint obj)
 {
     return(GetHashCode((ITypeDescriptor)obj.Constraint));
 }
Ejemplo n.º 11
0
 public static string ToString(this MetadataReader reader, GenericParameterConstraint x) => $"{{GenParamConstr[{RowId(x):X}]: {reader.ToString( x.Parameter)} {reader.ToString( x.Type)}}}";
Ejemplo n.º 12
0
 public static TypeReference GetConstraintType(this GenericParameterConstraint constraint)
 => constraint.ConstraintType;