Added beginning support for Dynamic Type Property Saving. Refer to my blog post for additional information in this: http://scionwest.net/2011/09/saving-type-data-dynamically/

Added new ParseProperty Attribute that must be used on any Type Property that will need to be saved during runtime.
This commit is contained in:
Scionwest_cp 2011-09-13 20:20:12 -07:00
parent f8620d0f4d
commit 81f2ae91c0
6 changed files with 537 additions and 471 deletions

View file

@ -4,14 +4,17 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.GameManagement;
using rScripting;
using rScripting.LateBinding;
namespace MudEngine.GameObjects
{
public class BaseObject
@ -175,6 +178,43 @@ namespace MudEngine.GameObjects
{
}
public virtual void NewSave()
{
ScriptObject obj = new ScriptObject(this);
PropertyInfo[] prop = this.GetType().GetProperties();
string path = this.SavePath;
if (String.IsNullOrEmpty(path))
return;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string filename = Path.Combine(path, Filename);
if (File.Exists(filename))
File.Delete(filename);
foreach (var p in prop)
{
object[] attributes = p.GetCustomAttributes(typeof(MudEngine.Attributes.ParseProperty), false);
foreach (Attribute a in attributes)
{
if (a.GetType().Name == "ParseProperty")
{
ParseProperty(p);
}
}
FileManager.WriteLine(filename, obj.GetProperty(p.Name).ToString(), p.Name);
}
}
private void ParseProperty(PropertyInfo propety)
{
}
public virtual void Save()
{
string path = this.SavePath;