Exemple #1
0
        internal CoreTypes(MetadataLoadContext loader, string?coreAssemblyName)
        {
            int numCoreTypes = (int)CoreType.NumCoreTypes;

            RoType?[]    coreTypes    = new RoType[numCoreTypes];
            Exception?[] exceptions   = new Exception[numCoreTypes];
            RoAssembly?  coreAssembly = loader.TryGetCoreAssembly(coreAssemblyName, out Exception? e);

            if (coreAssembly == null)
            {
                // If the core assembly was not found, don't continue.
                throw e !;
            }
            else
            {
                for (int i = 0; i < numCoreTypes; i++)
                {
                    ((CoreType)i).GetFullName(out byte[] ns, out byte[] name);
                    RoType?type = coreAssembly.GetTypeCore(ns, name, ignoreCase: false, out e);
                    coreTypes[i] = type;
                    if (type == null)
                    {
                        exceptions[i] = e;
                    }
                }
            }
            _coreTypes  = coreTypes;
            _exceptions = exceptions;
        }
        /// <summary>
        /// Returns a lazily created and cached Type instance corresponding to the indicated core type. This method throws
        /// if the core assembly name wasn't supplied, the core assembly could not be loaded for some reason or if the specified
        /// type does not exist in the core assembly.
        /// </summary>
        internal RoType GetCoreType(CoreType coreType)
        {
            CoreTypes coreTypes = GetAllFoundCoreTypes();
            RoType    t         = TryGetCoreType(coreType);

            return(t ?? throw coreTypes.GetException(coreType));
        }
        protected internal sealed override RoType ComputeEnumUnderlyingType()
        {
            //
            // This performs the functional equivalent of the base Type GetEnumUnderlyingType without going through all the BindingFlag lookup overhead.
            //

            if (!IsEnum)
            {
                throw new ArgumentException(SR.Arg_MustBeEnum);
            }

            MetadataReader reader         = Reader;
            TypeContext    typeContext    = Instantiation.ToTypeContext();
            RoType         underlyingType = null;

            foreach (FieldDefinitionHandle handle in TypeDefinition.GetFields())
            {
                FieldDefinition fd = handle.GetFieldDefinition(reader);
                if ((fd.Attributes & FieldAttributes.Static) != 0)
                {
                    continue;
                }
                if (underlyingType != null)
                {
                    throw new ArgumentException(SR.Argument_InvalidEnum);
                }
                underlyingType = fd.DecodeSignature(GetEcmaModule(), typeContext);
            }

            if (underlyingType == null)
            {
                throw new ArgumentException(SR.Argument_InvalidEnum);
            }
            return(underlyingType);
        }
        private RoType[] ComputeGenericTypeParameters()
        {
            EcmaModule module = GetEcmaModule();
            GenericParameterHandleCollection gps = TypeDefinition.GetGenericParameters();

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

            RoType[] genericParameters = new RoType[gps.Count];
            foreach (GenericParameterHandle h in gps)
            {
                RoType gp = h.ResolveGenericParameter(module);
                genericParameters[gp.GenericParameterPosition] = gp;
            }
            return(genericParameters);
        }
Exemple #5
0
        public                                  RoType[] ComputeGenericArgumentsOrParameters()
        {
            GenericParameterHandleCollection gphs = MethodDefinition.GetGenericParameters();
            int count = gphs.Count;

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

            RoType[] gps = new RoType[count];
            foreach (GenericParameterHandle gph in gphs)
            {
                RoType gp = gph.ResolveGenericParameter(_module);
                gps[gp.GenericParameterPosition] = gp;
            }
            return(gps);
        }
Exemple #6
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);
        }
        public sealed override MethodInfo GetGenericMethodDefinition() => IsGenericMethodDefinition ? this : throw new InvalidOperationException(); // Very uninformative but compatible exception

        public sealed override MethodInfo MakeGenericMethod(params Type[] typeArguments)
        {
            if (typeArguments == null)
            {
                throw new ArgumentNullException(nameof(typeArguments));
            }

            if (!IsGenericMethodDefinition)
            {
                throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericMethodDefinition, this));
            }

            int count = typeArguments.Length;

            RoType[] roTypeArguments = new RoType[count];
            for (int i = 0; i < count; i++)
            {
                Type typeArgument = typeArguments[i];
                if (typeArgument == null)
                {
                    throw new ArgumentNullException();
                }

                if (!(typeArgument is RoType roTypeArgument && roTypeArgument.Loader == Loader))
                {
                    throw new ArgumentException(SR.Format(SR.MakeGenericType_NotLoadedByMetadataLoadContext, typeArgument));
                }

                roTypeArguments[i] = roTypeArgument;
            }

            if (count != GetGenericTypeParametersNoCopy().Length)
            {
                throw new ArgumentException(SR.Argument_GenericArgsCount, nameof(typeArguments));
            }

            return(new RoConstructedGenericMethod(this, roTypeArguments));
        }
Exemple #8
0
        private Type[] GetCustomModifiers(bool isRequired)
        {
            RoType type = FieldDefinition.DecodeSignature(new EcmaModifiedTypeProvider(_module), TypeContext) !;

            return(type.ExtractCustomModifiers(isRequired));
        }
 public sealed override RoType GetPinnedType(RoType elementType) => new RoPinnedType(elementType);
 public sealed override RoType GetModifiedType(RoType modifier, RoType unmodifiedType, bool isRequired) => unmodifiedType;
Exemple #11
0
 public sealed override RoType GetPinnedType(RoType elementType) => elementType;
Exemple #12
0
 public sealed override RoType GetModifiedType(RoType modifier, RoType unmodifiedType, bool isRequired) => new RoModifiedType(modifier.SkipTypeWrappers(), unmodifiedType, isRequired);
 public static RoPointerType GetUniquePointerType(this RoType elementType) => elementType.GetRoModule().GetUniquePointerType(elementType);
 public static RoByRefType GetUniqueByRefType(this RoType elementType) => elementType.GetRoModule().GetUniqueByRefType(elementType);
 public static RoArrayType GetUniqueArrayType(this RoType elementType, int rank) => elementType.GetRoModule().GetUniqueArrayType(elementType, rank);
 internal RoPinnedType(RoType unmodifiedType)
     : base(unmodifiedType)
 {
 }