public SetBaseTypeConstraint ( System baseTypeConstraint ) : void | ||
baseTypeConstraint | System | |
return | void |
protected virtual unsafe void DefineGenericTypeParameter(TypeBuilder typeBuilder, GenericTypeParameterBuilder paramBuilder, BCSYM_GenericParam* pParam) { paramBuilder.SetGenericParameterAttributes(GetGenericParameterAttributes(pParam)); List<Type> list = new List<Type>(); for (BCSYM_GenericConstraint* constraintPtr = *((BCSYM_GenericConstraint**) (pParam + 0x54)); constraintPtr != null; constraintPtr = *((BCSYM_GenericConstraint**) (constraintPtr + 8))) { if (((byte) (*(((byte*) constraintPtr)) == 0x26)) != 0) { BCSYM* pSymbol = BCSYM.DigThroughNamedType(*((BCSYM* modopt(IsConst) modopt(IsConst)*) (constraintPtr + 12))); Type item = this.GetType(typeBuilder, pSymbol); if (BCSYM.IsInterface(pSymbol)) { list.Add(item); } else { paramBuilder.SetBaseTypeConstraint(item); } } } if (list.Count > 0) { paramBuilder.SetInterfaceConstraints(list.ToArray()); } }
internal void FinishDefinition(GenericTypeParameterBuilder arg) { Contracts.Require.IsNotNull("arg", arg); arg.SetGenericParameterAttributes(Attributes); if (_baseTypeConstraint != null) { arg.SetBaseTypeConstraint(_baseTypeConstraint.Target); } if (_interfaceConstraints.Count > 0) { arg.SetInterfaceConstraints((from i in _interfaceConstraints select i.Target).ToArray()); } }
private void DefineGenericParameter(InternalGenericParameter parameter, GenericTypeParameterBuilder builder) { // Set base type constraint if (parameter.BaseType != TypeSystemServices.ObjectType) { builder.SetBaseTypeConstraint(GetSystemType(parameter.BaseType)); } // Set interface constraints Type[] interfaceTypes = Array.ConvertAll<IType, Type>( parameter.GetInterfaces(), GetSystemType); builder.SetInterfaceConstraints(interfaceTypes); // Set special attributes GenericParameterAttributes attributes = GenericParameterAttributes.None; if (parameter.IsClass) attributes |= GenericParameterAttributes.ReferenceTypeConstraint; if (parameter.IsValueType) attributes |= GenericParameterAttributes.NotNullableValueTypeConstraint; if (parameter.MustHaveDefaultConstructor) attributes |= GenericParameterAttributes.DefaultConstructorConstraint; builder.SetGenericParameterAttributes(attributes); }
private static void UpdateGenericParameterContraints(RppGenericParameter genericParameter, GenericTypeParameterBuilder nativeGenericParameter) { if (genericParameter.Constraint != null) { if (genericParameter.Constraint.IsClass) { nativeGenericParameter.SetBaseTypeConstraint(genericParameter.Constraint.NativeType); } else { nativeGenericParameter.SetInterfaceConstraints(genericParameter.Constraint.NativeType); } } }
public void EmitConstraints (GenericTypeParameterBuilder builder) { var attr = GenericParameterAttributes.None; if (spec.Variance == Variance.Contravariant) attr |= GenericParameterAttributes.Contravariant; else if (spec.Variance == Variance.Covariant) attr |= GenericParameterAttributes.Covariant; if (spec.HasSpecialClass) attr |= GenericParameterAttributes.ReferenceTypeConstraint; else if (spec.HasSpecialStruct) attr |= GenericParameterAttributes.NotNullableValueTypeConstraint | GenericParameterAttributes.DefaultConstructorConstraint; if (spec.HasSpecialConstructor) attr |= GenericParameterAttributes.DefaultConstructorConstraint; if (spec.BaseType != TypeManager.object_type) builder.SetBaseTypeConstraint (spec.BaseType.GetMetaInfo ()); if (spec.InterfacesDefined != null) builder.SetInterfaceConstraints (spec.InterfacesDefined.Select (l => l.GetMetaInfo ()).ToArray ()); if (spec.TypeArguments != null) builder.SetInterfaceConstraints (spec.TypeArguments.Select (l => l.GetMetaInfo ()).ToArray ()); builder.SetGenericParameterAttributes (attr); }
public void SetConstraints (GenericTypeParameterBuilder type) { GenericParameterAttributes attr = GenericParameterAttributes.None; if (variance == Variance.Contravariant) attr |= GenericParameterAttributes.Contravariant; else if (variance == Variance.Covariant) attr |= GenericParameterAttributes.Covariant; if (gc != null) { if (gc.HasClassConstraint || gc.HasValueTypeConstraint) type.SetBaseTypeConstraint (gc.EffectiveBaseClass); attr |= gc.Attributes; type.SetInterfaceConstraints (gc.InterfaceConstraints); TypeManager.RegisterBuilder (type, gc.InterfaceConstraints); } type.SetGenericParameterAttributes (attr); }