示例#1
0
        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));
        }