예제 #1
0
        protected sealed override RoType[] ComputeGenericParameterConstraints()
        {
            MetadataReader reader = Reader;
            GenericParameterConstraintHandleCollection handles = GenericParameter.GetConstraints();
            int count = handles.Count;

            if (count == 0)
            {
                return(Array.Empty <RoType>());
            }

            RoType[] constraints = new RoType[count];
            int      index       = 0;

            foreach (GenericParameterConstraintHandle h in handles)
            {
                RoType constraint = h.GetGenericParameterConstraint(reader).Type.ResolveTypeDefRefOrSpec(GetEcmaModule(), TypeContext);
                constraints[index++] = constraint;
            }
            return(constraints);
        }
        private GenericParameterWrapper(AssemblyMetadata assemblyMetadata, IHandleTypeNamedWrapper owner, GenericParameterHandle handle, GenericParameterAttributes genericParameterAttribute)
        {
            AssemblyMetadata           = assemblyMetadata;
            Owner                      = owner;
            Handle                     = handle;
            _genericParameterAttribute = genericParameterAttribute;
            GenericParameter           = assemblyMetadata.MetadataReader.GetGenericParameter(handle);

            _attributes = new Lazy <IReadOnlyList <AttributeWrapper> >(() => AttributeWrapper.CreateChecked(GenericParameter.GetCustomAttributes(), assemblyMetadata), LazyThreadSafetyMode.PublicationOnly);
            _parent     = new Lazy <IHandleTypeNamedWrapper?>(() => WrapperFactory.Create(GenericParameter.Parent, assemblyMetadata), LazyThreadSafetyMode.PublicationOnly);
            _name       = new Lazy <string>(() => GenericParameter.Name.GetName(assemblyMetadata));
            switch (genericParameterAttribute & GenericParameterAttributes.VarianceMask)
            {
            case GenericParameterAttributes.Contravariant:
                Variance = VarianceType.Contravariant;
                break;

            case GenericParameterAttributes.Covariant:
                Variance = VarianceType.Covariant;
                break;

            default:
                Variance = VarianceType.Invariant;
                break;
            }

            _constraints = new Lazy <IReadOnlyList <GenericParameterConstraintWrapper> >(() => GenericParameterConstraintWrapper.CreateChecked(GenericParameter.GetConstraints(), this, AssemblyMetadata), LazyThreadSafetyMode.PublicationOnly);
        }