private void p_copyFrom(Expression rhs) { // copy recursively switch (rhs.ExpressionType) { case ExpressionType.Value: { m_type = ExpressionType.Value; m_value = new ExpressionPrivateValue(); m_value.Init(); m_value.data = rhs.m_value.data; break; } case ExpressionType.BinaryData: { m_type = ExpressionType.BinaryData; m_binaryData = new ExpressionPrivateBinaryData(); m_binaryData.Init(); m_binaryData.data = rhs.m_binaryData.data; break; } case ExpressionType.Array: { m_type = ExpressionType.Array; m_array = new ExpressionPrivateArray(); m_array.Init(); for (int i = 0; i < rhs.m_array.list.Count; ++i) { var child = rhs.ArrayAt(i); var childCopy = child.Copy(); // add to our array ArrayAddElementToEnd(childCopy); } break; } case ExpressionType.Map: { m_type = ExpressionType.Map; m_map = new ExpressionPrivateMap(); m_map.Init(); for (var i = 0; i < rhs.MapCount; ++i) { MapSetValueForKey( rhs.MapKeyAt(i), rhs.MapValueAt(i).Copy() ); } break; } default: { break; } // ignore } }
// /// <summary> /// Change the type of the expression. Invalidates all data currently in the expression. /// </summary> /// <param name="type">The new type of the expression.</param> // public void ChangeType(ExpressionType type) { // set and recreate our new type m_type = type; if (m_type == ExpressionType.Value) { m_value = new ExpressionPrivateValue(); m_value.Init(); } else if (m_type == ExpressionType.BinaryData) { m_binaryData = new ExpressionPrivateBinaryData(); m_binaryData.Init(); } else if (m_type == ExpressionType.Array) { m_array = new ExpressionPrivateArray(); m_array.Init(); } else if (m_type == ExpressionType.Map) { m_map = new ExpressionPrivateMap(); m_map.Init(); } }