0
下面是我的XML的LINQ to XML创建对象的基于子节点属性
<Test>
<Collection>
<abc Name="EmployeeId>1</abc>
<abc Name="EmployeeName>Test</abc>
</Collection>
<Collection>
<abc Name="EmployeeId "/>
<abc Name="EmployeeName"/>
</Collection>
<Collection>
<abc Name="InstituteId" />
<abc Name="InstituteName"/>
<abc Name="InstituteLocation"/>
</Collection>
<Collection>
<abc Name="InstituteId">1</abc>
<abc Name="InstituteName">Test Institute </abc>
<abc Name="InstituteLocation">Test Location</abc>
</Collection>
</Test>
下面是我的班。
Public class Employee
{
Public int Id { get; set; }
Public string Name { get; set; }
}
Public class Institution
{
Public int Id { get; set;}
Public string Name {get; set; }
Public string Location {get; set;}
}
如何按属性名称创建类,就像如果属性名称是instituteId不是创造研究所的对象,否则创建Employee对象
根据孩子的属性创建对象在C#中应该是一个简单的'if else'块。尝试实施,如果你还没有,显示你的尝试代码,并指出哪部分不按预期工作,或者你有麻烦实施正确... – har07