public void Cd(Path path, params object[] keys)
{
if (path == Path.Absolute)
{
m_cd = new IronJSONValue(m_obj);
m_curPath.Clear();
}
foreach (object o in keys)
{
if (o is int)
{
if (m_cd.Type != ValueType.Array)
throw new InvalidKeyException(CurrentPath + o.ToString());
try
{
m_cd = (IronJSONValue)m_cd.Array[(int)o];
}
// Out of range of the array.
catch (System.ArgumentOutOfRangeException)
{
throw new KeyNotFoundException(CurrentPath + o.ToString());
}
}
else if (o is string)
{
if (m_cd.Type != ValueType.Object)
throw new InvalidKeyException(CurrentPath + o.ToString());
else if (!m_cd.Obj.ContainsKey((string)o))
throw new KeyNotFoundException(CurrentPath + o.ToString());
m_cd = (IronJSONValue)m_cd.Obj[(string)o];
}
else
{
throw new InvalidKeyException(o.ToString());
}
// Validate, make sure we CDed to an object or array.
if (m_cd.Type != ValueType.Array && m_cd.Type != ValueType.Object)
throw new InvalidLocationException("change directory (Cd)", CurrentPath + o.ToString());
m_curPath.Add(o);
}
}