protected RoHasElementType(RoType elementType) : base() { Debug.Assert(elementType != null); _elementType = elementType; }
internal CoreTypes(TypeLoader loader) { int numCoreTypes = (int)CoreType.NumCoreTypes; RoType[] coreTypes = new RoType[numCoreTypes]; Exception[] exceptions = new Exception[numCoreTypes]; RoAssembly coreAssembly = loader.TryGetCoreAssembly(out Exception e); if (coreAssembly == null) { for (int i = 0; i < numCoreTypes; i++) { exceptions[i] = 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; }
public static Type[] ExtractCustomModifiers(this RoType type, bool isRequired) { int count = 0; RoType walk = type; while (walk is RoModifiedType roModifiedType) { if (roModifiedType.IsRequired == isRequired) { count++; } walk = roModifiedType.UnmodifiedType; } Type[] modifiers = new Type[count]; walk = type; int index = count; while (walk is RoModifiedType roModifiedType) { if (roModifiedType.IsRequired == isRequired) { modifiers[--index] = roModifiedType.Modifier; } walk = roModifiedType.UnmodifiedType; } Debug.Assert(index == 0); return(modifiers); }
private RoType[] ComputeInterfaceClosure() { HashSet <RoType> ifcs = new HashSet <RoType>(); RoType baseType = ComputeBaseTypeWithoutDesktopQuirk(); if (baseType != null) { foreach (RoType ifc in baseType.GetInterfacesNoCopy()) { ifcs.Add(ifc); } } foreach (RoType ifc in ComputeDirectlyImplementedInterfaces()) { bool notSeenBefore = ifcs.Add(ifc); if (notSeenBefore) { foreach (RoType indirectIfc in ifc.GetInterfacesNoCopy()) { ifcs.Add(indirectIfc); } } } return(ifcs.ToArray()); }
public Key(RoType elementType, int rank) { Debug.Assert(elementType != null); ElementType = elementType; Rank = rank; }
private RoType[] ComputeInterfaceClosure() { HashSet <RoType> ifcs = new HashSet <RoType>(); RoType baseType = ComputeBaseTypeWithoutDesktopQuirk(); if (baseType != null) { foreach (RoType ifc in baseType.GetInterfacesNoCopy()) { ifcs.Add(ifc); } } foreach (RoType ifc in ComputeDirectlyImplementedInterfaces()) { bool notSeenBefore = ifcs.Add(ifc); if (!notSeenBefore) { foreach (RoType indirectIfc in ifc.GetInterfacesNoCopy()) { ifcs.Add(indirectIfc); } } } // todo: use IEnumerable<T> extension: return ifcs.ToArray() List <RoType> list = new List <RoType>(ifcs); return(list.ToArray()); }
internal RoModifiedType(RoType modifier, RoType unmodifiedType, bool isRequired) : base(unmodifiedType) { Debug.Assert(modifier != null); Modifier = modifier; IsRequired = isRequired; }
public static RoType SkipTypeWrappers(this RoType type) { while (type is RoWrappedType roWrappedType) { type = roWrappedType.UnmodifiedType; } return(type); }
internal RoSyntheticConstructor(RoType declaringType, int uniquifier, params RoType[] parameterTypes) : base() { Debug.Assert(declaringType != null); _declaringType = declaringType; _uniquifier = uniquifier; _parameterTypes = parameterTypes; }
internal RoArrayType(RoType elementType, bool multiDim, int rank) : base(elementType) { Debug.Assert(elementType != null); Debug.Assert(multiDim || rank == 1); _multiDim = multiDim; _rank = rank; }
internal RoSyntheticMethod(RoType declaringType, int uniquifier, string name, RoType returnType, params RoType[] parameterTypes) : base(declaringType) { Debug.Assert(declaringType != null); _declaringType = declaringType; _uniquifier = uniquifier; _name = name; _returnType = returnType; _parameterTypes = parameterTypes; }
public static RoType LoadTypeFromAssemblyQualifiedName(string name, RoAssembly defaultAssembly, bool ignoreCase, bool throwOnError) { if (!name.TypeNameContainsTypeParserMetacharacters()) { // Fast-path: the type contains none of the parser metacharacters nor the escape character. Just treat as plain old type name. name.SplitTypeName(out string ns, out string simpleName); RoType type = defaultAssembly.GetTypeCore(ns, simpleName, ignoreCase: ignoreCase, out Exception e); if (type != null) { return(type); } if (throwOnError) { throw e; } } TypeLoader loader = defaultAssembly.Loader; Func <AssemblyName, Assembly> assemblyResolver = delegate(AssemblyName assemblyName) { return(loader.LoadFromAssemblyName(assemblyName)); }; Func <Assembly, string, bool, Type> typeResolver = delegate(Assembly assembly, string fullName, bool ignoreCase2) { if (assembly == null) { assembly = defaultAssembly; } Debug.Assert(assembly is RoAssembly); RoAssembly roAssembly = (RoAssembly)assembly; fullName = fullName.UnescapeTypeNameIdentifier(); fullName.SplitTypeName(out string ns, out string simpleName); Type type = roAssembly.GetTypeCore(ns, simpleName, ignoreCase: ignoreCase2, out Exception e); if (type != null) { return(type); } if (throwOnError) { throw e; } return(null); }; return((RoType)Type.GetType(name, assemblyResolver: assemblyResolver, typeResolver: typeResolver, throwOnError: throwOnError, ignoreCase: ignoreCase)); }
protected sealed override MethodSig <RoParameter> ComputeMethodSig() { int parameterCount = _parameterTypes.Length; MethodSig <RoParameter> sig = new MethodSig <RoParameter>(parameterCount); RoType returnType = GetRoModule().Loader.GetCoreType(CoreType.Void); sig[-1] = new RoThinMethodParameter(this, -1, returnType); for (int position = 0; position < parameterCount; position++) { sig[position] = new RoThinMethodParameter(this, position, _parameterTypes[position]); } return(sig); }
public sealed override Type MakeGenericType(params Type[] typeArguments) { if (typeArguments == null) { throw new ArgumentNullException(nameof(typeArguments)); } if (!IsGenericTypeDefinition) { throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this)); } int count = typeArguments.Length; if (count != GetGenericParameterCount()) { throw new ArgumentException(SR.Argument_GenericArgsCount, nameof(typeArguments)); } bool foundSigType = false; RoType[] runtimeTypeArguments = new RoType[count]; for (int i = 0; i < count; i++) { Type typeArgument = typeArguments[i]; if (typeArgument == null) { throw new ArgumentNullException(); } if (typeArgument.IsSignatureType()) { foundSigType = true; } else { if (!(typeArgument is RoType roTypeArgument && roTypeArgument.Loader == Loader)) { throw new ArgumentException(SR.Format(SR.MakeGenericType_NotLoadedByMetadataLoadContext, typeArgument)); } runtimeTypeArguments[i] = roTypeArgument; } } if (foundSigType) { return(this.MakeSignatureGenericType(typeArguments)); } // We are intentionally not validating constraints as constraint validation is an execution-time issue that does not block our // library and should not block a metadata inspection tool. return(this.GetUniqueConstructedGenericType(runtimeTypeArguments)); }
private string GetDefaultMemberName() { for (RoType type = this; type != null; type = type.GetRoBaseType()) { CustomAttributeData attribute = type.TryFindCustomAttribute(Utf8Constants.SystemReflection, Utf8Constants.DefaultMemberAttribute); if (attribute != null) { IList <CustomAttributeTypedArgument> fixedArguments = attribute.ConstructorArguments; if (fixedArguments.Count == 1 && fixedArguments[0].Value is string memberName) { return(memberName); } } } return(null); }
private RoType ComputeBaseType() { RoType baseType = ComputeBaseTypeWithoutDesktopQuirk(); if (baseType != null && baseType.IsGenericParameter) { // NETFX quirk: a generic parameter whose constraint is another generic parameter reports its BaseType as System.Object // unless that other generic parameter has a "class" constraint. GenericParameterAttributes genericParameterAttributes = baseType.GenericParameterAttributes; if (0 == (genericParameterAttributes & GenericParameterAttributes.ReferenceTypeConstraint)) { baseType = Loader.GetCoreType(CoreType.Object); } } return(baseType); }
internal sealed override IEnumerable <MethodInfo> GetMethodsCore(NameFilter filter, Type reflectedType) { int rank = _rank; int uniquifier = 0; RoType systemInt32 = Loader.GetCoreType(CoreType.Int32); RoArrayType arrayType = this; RoType elementType = GetRoElementType(); RoType systemVoid = Loader.GetCoreType(CoreType.Void); if (filter == null || filter.Matches("Get")) { RoType[] getParameters = new RoType[rank]; for (int i = 0; i < rank; i++) { getParameters[i] = systemInt32; } yield return(new RoSyntheticMethod(this, uniquifier++, "Get", elementType, getParameters)); } if (filter == null || filter.Matches("Set")) { RoType[] setParameters = new RoType[rank + 1]; for (int i = 0; i < rank; i++) { setParameters[i] = systemInt32; } setParameters[rank] = elementType; yield return(new RoSyntheticMethod(this, uniquifier++, "Set", systemVoid, setParameters)); } if (filter == null || filter.Matches("Address")) { RoType[] addressParameters = new RoType[rank]; for (int i = 0; i < rank; i++) { addressParameters[i] = systemInt32; } yield return(new RoSyntheticMethod(this, uniquifier++, "Address", elementType.GetUniqueByRefType(), addressParameters)); } }
protected sealed override IEnumerable <RoType> ComputeDirectlyImplementedInterfaces() { if (_multiDim) { yield break; } RoType[] typeArguments = { GetRoElementType() }; foreach (CoreType coreType in s_typesImplementedByArray) { RoType ifc = Loader.TryGetCoreType(coreType); if (ifc != null) { // All of our types are from a fixed list so we know they're supposed be generic interfaces taking one type parameter. // But since we're loading them from a core assembly that the user supplied us, we should verify and skip if // this is not the case. if (ifc is RoDefinitionType roDefinitionType && roDefinitionType.GetGenericParameterCount() == 1) { yield return(roDefinitionType.GetUniqueConstructedGenericType(typeArguments)); } } } }
private RoType[] ComputeInterfaceClosure() { HashSet <RoType> ifcs = new HashSet <RoType>(); RoType?baseType = ComputeBaseTypeWithoutDesktopQuirk(); if (baseType != null) { foreach (RoType ifc in baseType.GetInterfacesNoCopy()) { ifcs.Add(ifc); } } foreach (RoType ifc in ComputeDirectlyImplementedInterfaces()) { bool notSeenBefore = ifcs.Add(ifc); if (!notSeenBefore) { foreach (RoType indirectIfc in ifc.GetInterfacesNoCopy()) { ifcs.Add(indirectIfc); } } } if (ifcs.Count == 0) { return(Array.Empty <RoType>()); } var arr = new RoType[ifcs.Count]; ifcs.CopyTo(arr); return(arr); }
internal sealed override IEnumerable <ConstructorInfo> GetConstructorsCore(NameFilter filter) { if (filter == null || filter.Matches(ConstructorInfo.ConstructorName)) { int rank = _rank; bool multiDim = _multiDim; RoType systemInt32 = Loader.GetCoreType(CoreType.Int32); int uniquifier = 0; // // Expose a constructor that takes n Int32's (one for each dimension) and constructs a zero lower-bounded array. For example, // // String[,] // // exposes // // .ctor(int32, int32) // { RoType[] parameterTypes = new RoType[rank]; for (int i = 0; i < rank; i++) { parameterTypes[i] = systemInt32; } yield return(new RoSyntheticConstructor(this, uniquifier++, parameterTypes)); } if (!multiDim) { // // Jagged arrays also expose constructors that take multiple indices and construct a jagged matrix. For example, // // String[][][][] // // also exposes: // // .ctor(int32, int32) // .ctor(int32, int32, int32) // .ctor(int32, int32, int32, int32) // int parameterCount = 2; RoType elementType = GetRoElementType(); while (elementType.IsSZArray) { RoType[] parameterTypes = new RoType[parameterCount]; for (int i = 0; i < parameterCount; i++) { parameterTypes[i] = systemInt32; } yield return(new RoSyntheticConstructor(this, uniquifier++, parameterTypes)); parameterCount++; elementType = elementType.GetRoElementType(); } } if (multiDim) { // // Expose a constructor that takes n*2 Int32's (two for each dimension) and constructs a arbitrarily lower-bounded array. For example, // // String[,] // // exposes // // .ctor(int32, int32, int32, int32) // RoType[] parameterTypes = new RoType[rank * 2]; for (int i = 0; i < rank * 2; i++) { parameterTypes[i] = systemInt32; } yield return(new RoSyntheticConstructor(this, uniquifier++, parameterTypes)); } } }
// // SzArrays // internal RoArrayType GetUniqueArrayType(RoType elementType) { return(_szArrayDict.GetOrAdd(elementType, s_szArrayTypeFactory)); }
internal RoByRefType(RoType elementType) : base(elementType) { Debug.Assert(elementType != null); }
public static RoPointerType GetUniquePointerType(this RoType elementType) => elementType.GetRoModule().GetUniquePointerType(elementType);
// // Returns all of the directly declared members on the given TypeInfo whose name matches filter. If filter is null, // returns all directly declared members. // public abstract IEnumerable <M> CoreGetDeclaredMembers(RuntimeTypeInfo type, NameFilter filter, RuntimeTypeInfo reflectedType);
// // Pointers // internal RoPointerType GetUniquePointerType(RoType elementType) { return(_pointerDict.GetOrAdd(elementType, (e) => new RoPointerType(e))); }
internal RoPinnedType(RoType unmodifiedType) : base(unmodifiedType) { }
// // MdArrays // internal RoArrayType GetUniqueArrayType(RoType elementType, int rank) { return(_mdArrayDict.GetOrAdd(new RoArrayType.Key(elementType, rank: rank), s_mdArrayTypeFactory)); }
// // ByRefs // internal RoByRefType GetUniqueByRefType(RoType elementType) { return(_byRefDict.GetOrAdd(elementType, s_byrefTypeFactory)); }
public static RoByRefType GetUniqueByRefType(this RoType elementType) => elementType.GetRoModule().GetUniqueByRefType(elementType);
internal RoWrappedType(RoType unmodifiedType) { Debug.Assert(unmodifiedType != null); UnmodifiedType = unmodifiedType; }