2

这是查询

XDocument application = XDocument.Load(@".\..\..\XmlFile\" + xmlFileName); 
var elements = from p in application.Descendants("Function")
               where ((string)p.Attribute("Fnumber").Value.Trim() ==  (SourceCodeParser.fCount.ToString().Trim()) && (string)p.Attribute("MethodName").Value.Trim() == (methodName) && (string) p.Parent.Parent.Attribute("ClassName").Value.Trim()== (className))
               select p.Element("MethodDependencies");

下面是执行引发异常的查询的代码片段

foreach (var file in elements)
{
    file.Add(
        new XElement("MethodDependency",
            new XAttribute("MethodName", MethodName),
            new XAttribute("ObjectName", ObjectName),
            new XAttribute("CallNumber", SourceCodeParser.methodcallCount.ToString().Trim()),
            new XElement("Arguments")
       ));
}

这是 Xml 结构

<Classes>
  <Class ClassName="" ClassPath="" ModifiedDate="" CreationDate="" InheritedFrom="" Modifier="" Specifier="">
      <Functions>
        <Function ReturnType="" Fnumber="" AccessModifier="" AccessSpecifier="" MethodName="">
          <Dependencies />
          <MethodDependencies />
        </Function>
      </Functions>
  </Class>
</Classes>

此查询适用于其他文件,但在某些文件上抛出异常,尽管所有文件的代码都相同......

有什么建议吗?

4

0 回答 0