/// <summary> /// Adds the frame XML element. /// </summary> /// <param name="element">The element.</param> private void AddFrameXmlElement(XElement element) { // Get type and name from th element string type = element.Name.LocalName; string name = GetName(element); if (name != null) { Declaration declaration = new Declaration { DeclarationType = DeclarationType.Table, Name = name, Type = type }; declarationCodeSenseProvider.AddDeclaration(declaration); } }
private void AddTableDeclaration(TableDeclarationProvider tableDeclarationProvider, XElement doc, XElement table) { //Add a declaration to the global list var name = (string)table.Attribute("name"); string src = (string)table.Attribute("src"); XElement variableElement = doc.XPathSelectElement(String.Format("./variables/variable[@name='{0}']", name)); /// Added by LiXizhi. 2008.10.21. we now support namespace (ns) attribute to variables, so that a table can reside in a nested namespace. such as /// <variable name="Class1" type="Class1" ns="MyCompany.MyProject.Class1"/> String nameSpace = null; if (variableElement != null) { nameSpace = (String)variableElement.Attribute("ns"); } bool bSkipRootDeclaration = false; if (!String.IsNullOrEmpty(nameSpace)) { if (nameSpace.IndexOf('.') > 0) { bSkipRootDeclaration = true; String LastTableName = null; foreach (Match tableField in Regex.Matches(nameSpace, @"\w+")) { if (tableField.Value != null) { if (LastTableName == null) { LastTableName = tableField.Value; var d = new Declaration { Name = tableField.Value, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = tableField.Value, }; tableDeclarationProvider.AddDeclaration(d); } else { var d = new Declaration { Name = tableField.Value, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = tableField.Value, }; tableDeclarationProvider.AddFieldDeclaration(LastTableName, d); LastTableName = tableField.Value; } } } if (LastTableName != name) { var d = new Declaration { Name = name, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = name, }; tableDeclarationProvider.AddFieldDeclaration(LastTableName, d); } } } if (!bSkipRootDeclaration) { var d = new Declaration { Name = name, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = variableElement == null ? name : variableElement.Attribute("type").Value, }; tableDeclarationProvider.AddDeclaration(d); } // Check whether the table inherits declarations from another table XAttribute inherits = table.Attribute("inherits"); if (inherits != null) { // inherits is a comma-delimited list of tables that this table inherits from string[] inheritValues = inherits.Value.Split(','); foreach (string inheritValue in inheritValues) { // Query the table that the declarations should be inherited from XElement baseTable = doc.XPathSelectElement(String.Format("./tables/table[@name='{0}']", inheritValue.Trim())); // If the table was found, add each declaration from the base table if (baseTable != null) { baseTable.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element)); } } } // Go through all declarations and add them to the table table.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element, src)); }
private void AddTableDeclaration(TableDeclarationProvider tableDeclarationProvider, XElement doc, XElement table) { //Add a declaration to the global list var name = (string)table.Attribute("name"); XElement variableElement = doc.XPathSelectElement(String.Format("./variables/variable[@name='{0}']", name)); /// Added by LiXizhi. 2008.10.21. we now support namespace (ns) attribute to variables, so that a table can reside in a nested namespace. such as /// <variable name="Class1" type="Class1" ns="MyCompany.MyProject.Class1"/> String nameSpace = (String)variableElement.Attribute("ns"); bool bSkipRootDeclaration = false; if (!String.IsNullOrEmpty(nameSpace)) { if(nameSpace.IndexOf('.')>0) { bSkipRootDeclaration = true; String LastTableName=null; foreach (Match tableField in Regex.Matches(nameSpace, @"\w+")) { if(tableField.Value!=null) { if(LastTableName==null) { LastTableName = tableField.Value; var d = new Declaration { Name = tableField.Value, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = tableField.Value, }; tableDeclarationProvider.AddDeclaration(d); } else { var d = new Declaration { Name = tableField.Value, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = tableField.Value, }; tableDeclarationProvider.AddFieldDeclaration(LastTableName, d); LastTableName = tableField.Value; } } } if(LastTableName != name) { var d = new Declaration { Name = name, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = name, }; tableDeclarationProvider.AddFieldDeclaration(LastTableName, d); } } } if (!bSkipRootDeclaration) { var d = new Declaration { Name = name, DeclarationType = DeclarationType.Table, Description = string.Empty, Type = variableElement.Attribute("type").Value }; tableDeclarationProvider.AddDeclaration(d); } // Check whether the table inherits declarations from another table XAttribute inherits = table.Attribute("inherits"); if (inherits != null) { // inherits is a comma-delimited list of tables that this table inherits from string[] inheritValues = inherits.Value.Split(','); foreach (string inheritValue in inheritValues) { // Query the table that the declarations should be inherited from XElement baseTable = doc.XPathSelectElement(String.Format("./tables/table[@name='{0}']", inheritValue.Trim())); // If the table was found, add each declaration from the base table if (baseTable != null) baseTable.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element)); } } // Go through all declarations and add them to the table table.Elements().ForEach(element => AddDeclaration(tableDeclarationProvider, name, element)); }