/// <summary> /// Imports a dictionary identified by an import directive. /// </summary> private void Import(ImportDirective directive) { // check if already loaded. if (LoadedFiles.ContainsKey(directive.Namespace)) { return; } TypeDictionary dictionary = (TypeDictionary)Load( typeof(TypeDictionary), directive.Namespace, directive.Location, Assembly.GetExecutingAssembly()); // verify namespace. if (!String.IsNullOrEmpty(dictionary.TargetNamespace) && directive.Namespace != dictionary.TargetNamespace) { throw Exception("Imported dictionary '{0}' does not match uri specified: '{1}'.", dictionary.TargetNamespace, directive.Namespace); } // save file. LoadedFiles.Add(dictionary.TargetNamespace, dictionary); // import nested dictionaries. if (dictionary.Import != null) { for (int ii = 0; ii < dictionary.Import.Length; ii++) { Import(dictionary.Import[ii]); } } // import types. if (dictionary.Items != null) { foreach (DataType datatype in dictionary.Items) { ImportDataType(datatype, dictionary.TargetNamespace); } } }
/// <summary> /// Imports a dictionary identified by an import directive. /// </summary> private async Task Import(ImportDirective directive) { // check if already loaded. if (LoadedFiles.ContainsKey(directive.Namespace)) { return; } TypeDictionary dictionary = (TypeDictionary)Load(typeof(TypeDictionary), directive.Namespace, directive.Location); // verify namespace. if (!String.IsNullOrEmpty(dictionary.TargetNamespace) && directive.Namespace != dictionary.TargetNamespace) { throw Exception("Imported dictionary '{0}' does not match uri specified: '{1}'.", dictionary.TargetNamespace, directive.Namespace); } // save file. LoadedFiles.Add(dictionary.TargetNamespace, dictionary); // import nested dictionaries. if (dictionary.Import != null) { for (int ii = 0; ii < dictionary.Import.Length; ii++) { await Import(dictionary.Import[ii]).ConfigureAwait(false); } } // import types. if (dictionary.Items != null) { foreach (TypeDescription description in dictionary.Items) { ImportDescription(description, dictionary.TargetNamespace); } } }