public System.Type GetUnderlyingType(RuntimicSystemModel model, TypeReference typeReference) { if (typeReference.IsGenericParameter) { var bound = ResolveToBound_GenericParameter(model, (GenericParameter)typeReference); return(bound.UnderlyingType); } if (typeReference.IsGenericInstance) { throw new Exception("Should never happen."); //var genericInstance = (GenericInstanceType)typeReference; //var genericTypeDefinitionType = GetUnderlyingType(model, genericInstance.ElementType); //System.Type[] genericArguments = new System.Type[genericInstance.GenericArguments.Count]; //for (int i = 0; i < genericInstance.GenericArguments.Count; i++) //{ // genericArguments[i] = GetUnderlyingType(model, genericInstance.GenericArguments[i]); // if (genericArguments[i] == null) // { // throw new Exception("The underlying type was null."); // } //} //var result = XCommonAppPal.Api.Runtimic.Execution.Metadata.Assemblies.MakeGenericType(genericTypeDefinitionType, genericArguments); //return result; } return(Cecil.GetUnderlyingType(typeReference)); }
public ExecutionTypeNode_I Ensure(ExecutionEnsureContext context) { if (!context.IsConverted.HasValue) { throw new Exception("Expected conversion to be figured out."); } if (context.StructuralInputTypeNode.CecilTypeReference.IsNested && context.DeclaringType == null) { context.DeclaringType = Execution.Types.Ensuring.EnsureBound(context, context.StructuralInputTypeNode.CecilTypeReference.DeclaringType, cloneContext: true); } if (context.IsConverted.Value) { var conversion = context.Conversion; var structuralInputTypeNode = context.StructuralInputTypeNode; var metadataToken = structuralInputTypeNode.MetadataToken; var structuralAssembly = Conversion.Metadata.Assemblies.EnsureNode(context.Conversion, structuralInputTypeNode.Module.Assembly); var convertedModuleNode = Conversion.Metadata.Modules.Ensure(context.Conversion, structuralAssembly, structuralInputTypeNode.Module); var tableId = (int)(metadataToken & 0xFF000000); if (!convertedModuleNode.Tables.TryGetValue(tableId, out ConvertedTypeTable table)) { table = new ConvertedTypeTable(); convertedModuleNode.Tables.Add(tableId, table); } if (table.ByRow.TryGetValue((uint)context.RowId, out ConversionTypeNode conversionTypeNode)) { return(conversionTypeNode); } var converted = Conversion.Metadata.Members.Types.Creation.Create(conversion.RuntimicSystem, structuralInputTypeNode.CecilTypeReference); converted.Module = convertedModuleNode.ConvertedModule; conversionTypeNode = new ConversionTypeNode() { Assembly = structuralAssembly, ByReferenceType = null, Id = 0, InputStructuralNode = structuralInputTypeNode, IsByReferenceType = false, IsDerived = false, IsPointerType = false, MetadataToken = metadataToken, Module = convertedModuleNode, PointerType = null, Type = converted }; table.ByRow.Add((uint)context.RowId, conversionTypeNode); var convertedDeclaringType = context.ConvertedDeclaringType; Converted_BuildPhase1(conversion, structuralInputTypeNode, converted, convertedDeclaringType); Conversion.Metadata.Members.Types.Building.IfPossibleBuildPhase2(conversion, converted); return(conversionTypeNode); } else { var structuralInputTypeNode = context.StructuralInputTypeNode; if (structuralInputTypeNode.FullName == "Root.Code.Containers.E01D.Sorting.SortingContainer_I`1") { } var metadataToken = structuralInputTypeNode.MetadataToken; var boundAssembly = Bound.Metadata.Assemblies.EnsureNode(context.RuntimicSystem, structuralInputTypeNode.Module.Assembly); var boundModuleNode = Bound.Metadata.Modules.Ensuring.EnsureNode(context.RuntimicSystem, boundAssembly, structuralInputTypeNode.Module); var tableId = (int)(metadataToken & 0xFF000000); if (!boundModuleNode.Tables.TryGetValue(tableId, out BoundTypeTable table)) { table = new BoundTypeTable(); boundModuleNode.Tables.Add(tableId, table); } if (table.ByRow.TryGetValue((uint)context.RowId, out BoundTypeNode boundTypeNode)) { return(boundTypeNode); } //--------------------------------- // Conversion is going to occur. //--------------------------------- if (context.UnderlyingType == null) { context.UnderlyingType = Cecil.GetUnderlyingType(structuralInputTypeNode.CecilTypeReference); if (context.UnderlyingType == null) { throw new Exception("Null type"); } } var bound = Bound.Metadata.Members.Types.Creation.Create(context.RuntimicSystem, context.StructuralInputTypeNode.CecilTypeReference, context.UnderlyingType); boundTypeNode = new BoundTypeNode() { Assembly = boundAssembly, ByReferenceType = null, Id = 0, InputStructuralNode = structuralInputTypeNode, IsByReferenceType = false, IsDerived = false, IsPointerType = false, MetadataToken = metadataToken, Module = boundModuleNode, PointerType = null, Type = bound }; bound.Module = boundModuleNode.BoundModule; //// Add the type instance to the model. Do not do any recursive calls till this methods is called. table.ByRow.Add((uint)context.RowId, boundTypeNode); //Types.Addition.Add(semanticModel, boundModule, bound); Bound.Metadata.Members.Types.Building.NonGenericInstances.Phase1Initial.Build(context.RuntimicSystem, bound, context.UnderlyingType, context.DeclaringType); return(boundTypeNode); } }