SetGenericParameterAttributes() public method

public SetGenericParameterAttributes ( System genericParameterAttributes ) : void
genericParameterAttributes System
return void
コード例 #1
0
 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());
     }
 }
コード例 #3
0
ファイル: EmitAssembly.cs プロジェクト: Bombadil77/boo
        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);
        }
コード例 #4
0
ファイル: ReflectionEmitter.cs プロジェクト: furesoft/roslyn
        private void DefineGenericParameterConstraints(GenericTypeParameterBuilder gpBuilder, Cci.IGenericParameter typeParameter)
        {
            List<Type> typeConstraints = new List<Type>();
            foreach (var constraint in typeParameter.GetConstraints(_context))
            {
                // generic constraints must be loaded before the declaring type:
                var typeConstraint = ResolveType(constraint, dependentType: (TypeBuilder)gpBuilder.DeclaringType, valueTypeDependency: false);
                typeConstraints.Add(typeConstraint);
            }

            // The types actually don't need to be interfaces. Ref.Emit merges them eventually with base type constraint into a single list.
            // Besides there might be multiple non-interface constraints applied on the parameter if they are another type parameters.
            gpBuilder.SetInterfaceConstraints(typeConstraints.ToArray());

            gpBuilder.SetGenericParameterAttributes(GetGenericParameterAttributes(typeParameter));
        }
コード例 #5
0
ファイル: generic.cs プロジェクト: ikvm/mono
		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);
		}
コード例 #6
0
		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);
		}