XML을 업데이트하는 기능을 쓰고 있으며 몇 가지 문제가 있습니다. 이전 XElement를 업데이트 된 버전으로 직접 설정할 수는 있지만 foreach 루프에서는 작동하지 않습니다 (단 하나의 쿼리 결과 여야 함). 각 필드를 하드 코딩하려고했지만 루프를 사용하기로 결정했습니다. 이 섹션을 명중하고 하위 요소는 단일 요소로 모두를 읽고 그리고 파일을 엉망 그러나 때복잡한 XML로 데이터 업데이트
var myDevice = from c in appDataXml.Descendants("device")
where (string)c.Element("name") == App.CurrentDeviceName
&& (string)c.Element("ip") == App.CurrentIp
select c;
if (myDevice.Any())
{
foreach (XElement device in myDevice)
{
//device.Element("customname").Value = updatedDevice.Element("customname").Value;
for (int a = 0; a < device.Elements().Count(); a++)
{
string field = device.Elements().ElementAt(a).Name.ToString();
device.Element(field).Value = updatedDevice.Element(field).Value;
}
}
}
샘플 XML은
<Devices>
<device>
<name>blah</name>
<customname>custom</customname>
<ip>192.168.1.100</ip>
<port>1000</port>
<sources>
<source>
<code>00</code>
<name>blah2</name>
<hidden>False</hidden>
</source>
<source>
...etc
</sources>
</device>
Windows Phone 7 프로젝트가 중요하다고 생각됩니다. Extender가 사용하는 TypeDescriptor가 구현되지 않은 것처럼 보입니다 – Jason
직접 시도해 볼 수 있습니다. http : // msdn.microsoft.com/en-us/library/ayybcxe5.aspx –
또는'GetString()'을 사용하는'GetInt()','GetBool()'등을 만들 수 있습니다. 예를 들어 int,'GetInt() {return Convert.ToInt32 (GetString (...)); } ' –