/// <summary> /// Gets the runtime data type for the given data type id. /// In case of generated types, this call might result in a interface code compilation. /// </summary> /// <param name="dataTypeDescriptor"> /// The DataTypeDescriptor for the data type. /// </param> /// <returns>Returns the data type. Never null.</returns> public static Type GetDataType(DataTypeDescriptor dataTypeDescriptor) { Verify.ArgumentNotNull(dataTypeDescriptor, "dataTypeDescriptor"); Type loadedDataType = _LoadedDataTypes.FirstOrDefault(f => f.FullName == dataTypeDescriptor.GetFullInterfaceName()); if (loadedDataType != null) { return(loadedDataType); } Type type = InterfaceCodeManager.GetType(dataTypeDescriptor); return(type); }
internal static Dictionary <Guid, Type> GetDataTypes(IReadOnlyCollection <DataTypeDescriptor> dataTypeDescriptors) { var result = new Dictionary <Guid, Type>(); var toCompile = new List <DataTypeDescriptor>(); foreach (var dataTypeDescriptor in dataTypeDescriptors) { string typeFullName = dataTypeDescriptor.GetFullInterfaceName(); Type type = _LoadedDataTypes.FirstOrDefault(f => f.FullName == typeFullName); if (type == null) { bool compilationNeeded; type = InterfaceCodeManager.TryGetType(dataTypeDescriptor, false, out compilationNeeded); if (compilationNeeded) { toCompile.Add(dataTypeDescriptor); } } if (type != null) { result[dataTypeDescriptor.DataTypeId] = type; } } if (toCompile.Any()) { var codeGenerationBuilder = new CodeGenerationBuilder("DataTypeTypesManager:compiling missing interfaces"); foreach (var dataTypeDescriptor in toCompile) { InterfaceCodeGenerator.AddAssemblyReferences(codeGenerationBuilder, dataTypeDescriptor); InterfaceCodeGenerator.AddInterfaceTypeCode(codeGenerationBuilder, dataTypeDescriptor); } var types = CodeGenerationManager.CompileRuntimeTempTypes(codeGenerationBuilder); var typesMap = types.ToDictionary(type => type.FullName); foreach (var dataTypeDescriptor in toCompile) { var type = typesMap[dataTypeDescriptor.GetFullInterfaceName()]; result[dataTypeDescriptor.DataTypeId] = type; } } return(result); }