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; }
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); } }
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()), });
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)); }
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); }
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); }
public void FixPlatformVersion(GenericParameterConstraint constraint) { if (constraint == null) { return; } FixPlatformVersion(constraint.ConstraintType); if (constraint.HasCustomAttributes) { foreach (CustomAttribute ca in constraint.CustomAttributes) { FixPlatformVersion(ca); } } }
/// <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); }
public int GetHashCode(GenericParameterConstraint obj) { return(GetHashCode((ITypeDescriptor)obj.Constraint)); }
public static string ToString(this MetadataReader reader, GenericParameterConstraint x) => $"{{GenParamConstr[{RowId(x):X}]: {reader.ToString( x.Parameter)} {reader.ToString( x.Type)}}}";
public static TypeReference GetConstraintType(this GenericParameterConstraint constraint) => constraint.ConstraintType;