示例#1
0
        public void ImportContext(string relativePath)
        {
            XElement element = XElement.Load(Path.Combine(Path.GetDirectoryName(FilePath), relativePath));

            // The SchemaModel deserializer relies on parent schemas existing in the context.
            // Therefore, I must immediately add them to this.Schemas as I create them.
            var schemas = new List <SchemaModel>();

            foreach (var schema in element.Elements("Schema")
                     .Select(e => new SchemaModel(this, e, isExternal: true)))
            {
                schemas.Add(schema);
                Schemas.AddRange(schema);
            }
            imports.Add(new ImportedContext(relativePath, element.Attribute("Name").Value, element.Attribute("Namespace").Value, schemas));
            OnTreeChanged();
        }
示例#2
0
        ///<summary>Loads a <see cref="DataContextModel"/> from an XML file, resolving relative paths to external schemas.</summary>
        public DataContextModel(string path)
            : this()
        {
            FilePath = path;
            var element = XElement.Load(path);

            Name      = element.Attribute("Name").Value;
            Namespace = element.Attribute("Namespace").Value;

            if (element.Attribute("CodePath") != null)              //This property was introduced later; I must accept older files
            {
                CodePath = element.Attribute("CodePath").Value;
            }

            foreach (var import in element.Elements("Import"))
            {
                ImportContext(import.Attribute("Path").Value);
            }

            Schemas.AddRange(element.Elements("Schema").Select(e => new SchemaModel(this, e)));
        }