그래서 XML 파일을 deserialize하는 데 문제가 있습니다.
다음 구조체를 사용하고 있습니다. Strange XmlSerializer 동작
[Serializable]
public struct GraphicsOptions
{
public int Height;
public int Width;
public bool Fullscreen;
public bool AntiAliasing;
public int ClickResCount;
}
그리고 만들려면 다음 코드
, 세 번째 이후를 제외하고public void CreateData()
{
graphicsOptions.Height = graphics.PreferredBackBufferHeight;
graphicsOptions.Width = graphics.PreferredBackBufferWidth;
graphicsOptions.Fullscreen = graphics.IsFullScreen;
graphicsOptions.AntiAliasing = graphics.PreferMultiSampling;
graphicsOptions.ClickResCount = 1;
dataStream = File.Create(SavegamePath);
XmlSerializer serializer = new XmlSerializer(typeof(GraphicsOptions));
serializer.Serialize(dataStream, graphicsOptions);
dataStream.Close();
}
변화와
private void ApplyChanges()
{
graphicsOptions.Height = graphics.PreferredBackBufferHeight;
graphicsOptions.Width = graphics.PreferredBackBufferWidth;
graphicsOptions.Fullscreen = graphics.IsFullScreen;
graphicsOptions.AntiAliasing = graphics.PreferMultiSampling;
graphicsOptions.ClickResCount = clickCountResolution;
dataStream = File.Open(SavegamePath, FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(GraphicsOptions));
serializer.Serialize(dataStream, graphicsOptions);
dataStream.Close();
}
로드 XML 파일
public void LoadData()
{
dataStream = File.Open(SavegamePath, FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(GraphicsOptions));
graphicsOptions = (GraphicsOptions)serializer.Deserialize(dataStream);
dataStream.Close();
}
꽤 표준 물건, 나는 그것의 변화를 적용한다. 파일 끝 부분에 2자를 추가합니다. "s>"
.
이유는 모르겠지만이 정보를 내 구조체에로드 할 수 없으므로 XML을 실질적으로 쓸모 없게 만듭니다.
Visual Studio에서 을 제공합니다. InvalidOperationException (왜 이렇게하는지 이해합니다).
발생을 방지하는 방법에 대한 조언이나 아이디어 또는 예외를 잡으면 2자를 삭제하는 방법은 무엇입니까?
참조하십시오. –
너무 많은 정보를 주었거나 충분하지 못했습니까? 문제의 프로그램은 XNA 프레임 워크로 만들었지 만 업데이트 논리를 추가 할 수는 있지만 실제로는 더 이상 정보를주지 못합니다. – Matonster
혼합 - 너무 많은 (즉, 쓸데없는 물건)과 충분하지 않은 (짧지 만 완전한 프로그램은 아닙니다. 문제). XNA는 아마 * 관련이 없습니다.하지만 문제를 보여주는 짧은 콘솔 앱 (스 니펫이 아닌 전체 프로그램)을 만들 것인지 쉽게 알 수 있습니다. –