using System.Collections.Generic;
///
/// A bundle holds data that will be saved to disk later.
///
public class Bundle
{
#region Fields
private readonly Dictionary _data;
///
/// Returns the amount of data included.
///
public int Count {
get {
return _data.Count;
}
}
#endregion
#region Constructors
public Bundle (Dictionary data)
{
_data = data;
}
public Bundle () : this (new Dictionary ())
{
}
#endregion
#region Put Methods
public Bundle Put (string key, object obj)
{
_data.Add (key, obj);
return this;
}
public Bundle PutString (string key, string str)
{
_data.Add (key, str);
return this;
}
public Bundle PutInt (string key, int i)
{
_data.Add (key, i);
return this;
}
public Bundle PutFloat (string key, float f)
{
_data.Add (key, f);
return this;
}
public Bundle PutBundle (string key, Bundle bundle)
{
_data.Add (key, bundle);
return this;
}
#endregion
#region Get Methods
public object Get (string key)
{
return _data [key];
}
public string GetString (string key)
{
var obj = _data [key];
return obj as string;
}
public int GetInt (string key)
{
var obj = _data [key];
if (obj is int) {
return (int)obj;
}
return -1;
}
public float GetFloat (string key)
{
var obj = _data [key];
if (obj is float) {
return (float)obj;
}
return -1;
}
public Bundle GetBundle (string key)
{
var obj = _data [key];
return obj as Bundle;
}
#endregion
}