Jypeli  9
The simple game programming library
Serialization.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 using System.IO;
3 
4 namespace Jypeli
5 {
6  public partial class FileManager
7  {
8  public LoadState BeginLoad( string fileName )
9  {
10  return new LoadState( this, fileName );
11  }
12 
13  internal LoadState BeginLoad( StorageFile file, string fileName )
14  {
15  return new LoadState( file, fileName );
16  }
17 
18  public SaveState BeginSave( string tag )
19  {
20  return new SaveState( this, tag );
21  }
22 
23  public T Load<T>( T obj, string fileName )
24  {
25  if ( !Exists( fileName ) )
26  throw new FileNotFoundException();
27 
28  LoadState state = BeginLoad( fileName );
29  T result = state.Load<T>( obj, "default" );
30  state.EndLoad();
31  return result;
32  }
33 
34  public T TryLoad<T>( T obj, string fileName )
35  {
36  try
37  {
38  return Load<T>( obj, fileName );
39  }
40  catch ( Exception )
41  {
42  return obj;
43  }
44  }
45 
46  public void Save<T>( T obj, string fileName )
47  {
48  SaveState state = BeginSave( fileName );
49  state.Save( obj, typeof( T ), "default" );
50  state.EndSave();
51  }
52 
53  public void TrySave<T>( T obj, string fileName )
54  {
55  try
56  {
57  Save<T>( obj, fileName );
58  }
59  catch ( Exception )
60  {
61  }
62  }
63 
64  public void Save( object obj, string fileName )
65  {
66  SaveState state = BeginSave( fileName );
67  state.Save( obj, obj.GetType(), "default" );
68  state.EndSave();
69  }
70 
71  public void TrySave( object obj, string fileName )
72  {
73  try
74  {
75  Save( obj, fileName );
76  }
77  catch ( Exception )
78  {
79  }
80  }
81 
87  public void Export( Stream objStream, string fileName )
88  {
89  using ( var f = Create( fileName ) )
90  {
91  objStream.CopyStreamTo( f.Stream );
92  }
93  }
94  }
95 }
Jypeli.StorageFile
Tiedosto.
Definition: StorageFile.cs:17
Jypeli.LoadState
Definition: LoadState.cs:9
Jypeli
Definition: Automobile.cs:5
Jypeli.FileManager.TrySave
void TrySave(object obj, string fileName)
Definition: Serialization.cs:71
Jypeli.FileManager.BeginLoad
LoadState BeginLoad(string fileName)
Definition: Serialization.cs:8
Jypeli.FileManager.Save
void Save(object obj, string fileName)
Definition: Serialization.cs:64
Jypeli.FileManager.BeginLoad
LoadState BeginLoad(StorageFile file, string fileName)
Definition: Serialization.cs:13
Jypeli.SaveState.EndSave
void EndSave()
Definition: SaveState.cs:64
Jypeli.FileManager.Exists
abstract bool Exists(string fileName)
Jypeli.FileManager.Load< T >
T Load< T >(T obj, string fileName)
Definition: Serialization.cs:23
Jypeli.FileManager.Export
void Export(Stream objStream, string fileName)
Vie virran sisällön tiedostoon.
Definition: Serialization.cs:87
Jypeli.FileManager.Create
StorageFile Create(string fileName)
Definition: Files.cs:10
Jypeli.FileManager.TrySave< T >
void TrySave< T >(T obj, string fileName)
Definition: Serialization.cs:53
Jypeli.LoadState.EndLoad
void EndLoad()
Definition: LoadState.cs:31
Jypeli.SaveState.Save
void Save(object obj, Type objType, string name)
Definition: SaveState.cs:47
System
Definition: CFFauxAttributes.cs:29
Jypeli.FileManager.Save< T >
void Save< T >(T obj, string fileName)
Definition: Serialization.cs:46
Jypeli.LoadState.Load
object Load(object obj, Type type, string name)
Definition: LoadState.cs:90
Jypeli.SaveState
Definition: SaveState.cs:9
Jypeli.FileManager.TryLoad< T >
T TryLoad< T >(T obj, string fileName)
Definition: Serialization.cs:34
Jypeli.FileManager.BeginSave
SaveState BeginSave(string tag)
Definition: Serialization.cs:18