XML 파일에서 특수 클래스로 정의 된 글꼴을 읽으려고합니다.C에서 문자열 변환 xmlreader.value
재미있는 점은 숫자를 읽고 int로 구문 분석하거나 심지어 16 진수 값을 가져올 수 있다는 것입니다. 3을 사용하거나 ARGB 값을 얻기 위해 부분을 "잘라 내기"하지만 가장 간단한 부분은 사용할 수 없습니다.
내 XML 리더 문자열 값을 설정하지 않으 :
myFont.name = xReader.Value.ToString();
난 항상 빈 myFont.name
의 가치, 나는 하나의 문자를 잘라하려고 노력하고 하나 하나를 추가 해요 경우에도 myFont.name
문자열 (내 절망적 인 결정)
하울 내가 말했듯이 R, I는 같은 방법을 사용하여 INT 값을 읽을 수 있습니다
이myFont.size = int.Parse(xReader.Value.ToString());
//returns correct value for the size
나는 또한 콘솔 창에 표시 할 수 있습니다
Console.Writeline(xReader.Value); //returns correct string
myFont.name=xReader.Value;
Console.Writeline(myFont.name.ToString()); //returns empty string
어떤 아이디어?
편집 : 글꼴 클래스 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6.entities
{
public class PDFFont
{
public int size { get; set; }
public int ColorR { get; set; }
public int ColorG { get; set; }
public int ColorB { get; set; }
public int ColorA { get; set; }
public string name { get; set; }
}
}
EDIT2 : 스위치 케이스 건설 :
while (Xread.MoveToNextAttribute())
{
entities.PDFFont newFont = new entities.PDFFont();
switch (Xread.Name)
{
case "name":
newFont.name = Xread.Value.ToString();
//returns null
break;
case "size": newFont.size = int.Parse(Xread.Value.ToString()); break;
//returns null, however before I create method below worked ok
case "color":
colorCreator nColor = new colorCreator(Xread.Value);
newFont.ColorR = nColor.R;
newFont.ColorG = nColor.G;
newFont.ColorB = nColor.B;
newFont.ColorA = nColor.A;
//works perfectly, values are transfer corectly
break;
}
나는 또 다른 객체에, 스위치 케이스 건설 바깥이 값을 설정하기 위해 시도하고 작동합니다. 그래서 위의 부분에 문제가 있습니다. 방금 console.writeline을 넣었습니다 ("들었습니다!"); newFont.name = xRead.Value와 break 사이에 있으며, 그 자체를 보여줍니다. 그래서 나는 그 사건 "이름"이 내 XML 파일에서 발견되었음을 안다.
XML을 표시하고 XML (또는 적어도 문제를 일으키는 특정 부분) 및 myfont의 속성 정의를 읽는 방법을 보여줄 수 있습니까? – Icepickle
당신은 myFont의 defn을 보여줄 수 있습니까? 기본적으로 이름 속성의 설정자에 문제가 있음을 보여줍니다. – cjb110
어디서나 ToString()을 오버라이드하고 있습니까? – Saggio