2014-12-17 2 views
1

나는 바이너리 plist를 읽고 XML 파일로 일부 데이터를 출력하지만, 다소 장애물에 부딪혔습니다. 나는 이런 식으로 뭔가하고 싶은XElements의 변수 번호를 추가하십시오.

BinaryPlistReader bpr = new BinaryPlistReader(); 
IDictionary plist = bpr.ReadObject(outputFolder + "\\Info.plist"); 
string name = plist["CFBundleName"].ToString(); 
string bundle = plist["CFBundleIdentifier"].ToString(); 
var icons = plist["CFBundleIconFiles"]; 

XElement apps = 
    new XElement("Applications", 
     new XElement("Application", 
      new XAttribute("Name", name), 
      new XAttribute("CFBundleIdentifier", bundle), 

      new XElement("Icon", "filename", 
       new XAttribute("Size", "icon size") 
       ) 
      ) 
     ); 
apps.Save(outputFolder + "\\" + name + ".xml"); 

: 여기에 내 현재 코드입니다

XElement apps = 
    new XElement("Applications", 
     new XElement("Application", 
      new XAttribute("Name", name), 
      new XAttribute("CFBundleIdentifier", bundle), 

      foreach (var icon in icons) 
      { 
       // Calculate icon size 
       new XElement("Icon", icon, 
        new XAttribute("Size", iconsize) 
      } 
       ) 
      ) 
     ); 
apps.Save(outputFolder + "\\" + name + ".xml"); 

을하지만 나는 XElement를 내 정의의 중간에 열거를 가질 수 없습니다, 그래서 난 이 작업을 수행하는 방법을 모릅니다. 지난 1 시간 동안 SO 답변을 보았음에도 불구하고 내 아이콘 개체를 통해 열거하는 방법을 실제로 알지 못합니다.

누군가 나를 도와 줄 수 있다면 정말 고맙겠습니다.

답변

1

당신은 너무 많은 LINQ

XElement apps = 
new XElement("Applications", 
    new XElement("Application", 
     new XAttribute("Name", name), 
     new XAttribute("CFBundleIdentifier", bundle), 
     (from icon in icons 
     select new XElement("Icon", icon, 
       new XAttribute("Size", iconsize))) 
     ) 
    ); 
+0

감사를 사용할 수 있습니다, 내 LINQ는 끔찍하다. 그래도이 오류가 표시됩니다. "원본 유형 '개체'에 대한 쿼리 패턴 구현을 찾을 수 없습니다. '선택'을 찾을 수 없습니다." 개체를 통해 열거 할 수있는 방법은 무엇입니까? 나는 지금까지 그들과 함께 일한 적이 없다. – tom982

+0

아이콘의 종류는 무엇입니까? 'System.Linq;을 사용하면됩니다. –

+0

System.Object []. 고마워, 이미 내 네임 스페이스에있다. – tom982

관련 문제