我有以下 xml 结构,我想将此 xml 转换为 CLR 对象,但我被卡住了。
<?xml version="1.0" encoding="utf-8"?>
<SymbolData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
assembly="C:\adCenter\debug\DLLs\Microsoft.Advertiser.CampaignManagement.BusinessRules.dll">
<sourceFiles>
<document id="1"
url="d:\7018\4579\Sources\Live\Microsoft.Advertiser.CampaignManagement.BusinessRules\AdExtensionValidators\AdExtensionValidationBatchErrors.cs"
language="3f5162f8-07c6-11d3-9053-00c04fa302a1"
languageVendor="994b45c4-e6e9-11d2-903f-00c04fa302a1"
documentType="5a869d0b-6611-11d3-bd2a-0000f80849bd" />
<document id="2"
url="d:\7018\4579\Sources\Live\Microsoft.Advertiser.CampaignManagement.BusinessRules\AdExtensionValidators\AdExtensionValidationBatchErrors.cs"
language="3f5162f8-07c6-11d3-9053-00c04fa302a1"
languageVendor="994b45c4-e6e9-11d2-903f-00c04fa302a1"
documentType="5a869d0b-6611-11d3-bd2a-0000f80849bd" />
</sourceFiles>
<method name="Microsoft.Advertiser.CampaignManagement.BusinessRules.AdExtensionValidators.AdExtensionValidationBatchErrors::.ctor"
token="0x600000c">
<sequencePoints>
<seqPoint ilOffset="0" sourceId="1" startRow="10" startColumn="9" endRow="10" endColumn="106" />
<seqPoint ilOffset="11" sourceId="1" startRow="12" startColumn="9" endRow="12" endColumn="136" />
<seqPoint ilOffset="22" sourceId="1" startRow="14" startColumn="9" endRow="14" endColumn="181" />
<seqPoint ilOffset="33" sourceId="1" hidden="true" startRow="16707566" startColumn="0" endRow="16707566" endColumn="0" />
</sequencePoints>
<rootScope implicit="true" startOffset="0" endOffset="40">
<scope startOffset="0" endOffset="40" isReconstructedDueToDiasymreaderBug="true" />
</rootScope>
<symAttributes />
<csharpCustomDebugInfo version="4">
<entries>
<usingForward version="4" tokenToForwardTo="0x6000001" />
</entries>
</csharpCustomDebugInfo>
</method>
<method name="Microsoft.Advertiser.CampaignManagement.BusinessRules.AdExtensionValidators.AdExtensionValidationError::ToString" token="0x600000f">
<sequencePoints>
<seqPoint ilOffset="0" sourceId="2" startRow="167" startColumn="13" endRow="167" endColumn="110" />
</sequencePoints>
<rootScope implicit="true" startOffset="0" endOffset="33">
<scope startOffset="0" endOffset="33" isReconstructedDueToDiasymreaderBug="true" />
</rootScope>
<symAttributes />
<csharpCustomDebugInfo version="4">
<entries>
<usingForward version="4" tokenToForwardTo="0x600000d" />
</entries>
</csharpCustomDebugInfo>
</method>
</SymbolData>
我已经编写了以下代码来实现相同的目标,但我无法查询方法部分。 例如,我想加载 documentID 和 SourceID 相同的所有方法。
public class ClassDetails
{
public string Id { get; set; }
public string Name { get; set; }
}
public class AssemblyDetails
{
public string DllName { get; set; }
public List<ClassDetails> Classes { get; set; }
public List<string> Methods { get; set; }
}
class Program
{
static void Main(string[] args)
{
var document = XDocument.Load("test11.xml");
var query = from descendantNode in document.Descendants("sourceFiles")
select new AssemblyDetails()
{
DllName = document.Root.Attribute("assembly").Value,
Classes = (from x in document.Descendants("document")
select new ClassDetails
{
Id=x.Attribute("id").Value,
Name=x.Attribute("url").Value
}).ToList(),
Methods = (from y in document.Descendants("method").Elements("seqPoint")
where y.Attribute("sourceId").Value=="documentID"
select y.Document.Root.Attribute("name").Value).ToList()
};
int i=10;
}