// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
namespace System.Json
{
///
/// Provide data for the and events.
///
public class JsonValueChangeEventArgs : EventArgs
{
private JsonValue child;
private JsonValueChange change;
private int index;
private string key;
///
/// Initializes a new instance of the class for
/// changes in a .
///
/// The instance which will be or has been modified.
/// The type of change of the event.
/// The index of the element being changed in a .
public JsonValueChangeEventArgs(JsonValue child, JsonValueChange change, int index)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException("index", RS.Format(Properties.Resources.ArgumentMustBeGreaterThanOrEqualTo, index, 0));
}
this.child = child;
this.change = change;
this.index = index;
}
///
/// Initializes a new instance of the class for
/// changes in a .
///
/// The instance which will be or has been modified.
/// The type of change of the event.
/// The key of the element being changed in a .
public JsonValueChangeEventArgs(JsonValue child, JsonValueChange change, string key)
{
if (change != JsonValueChange.Clear)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
}
this.child = child;
this.change = change;
index = -1;
this.key = key;
}
///
/// Gets the child which will be or has been modified.
///
///
This property is null for event types
/// raised by instances.
///
For Replace events, this property contains the new value in
/// the event, and the old value (the one being replaced) in the
/// event.
public JsonValue Child
{
get { return child; }
}
///
/// Gets the type of change.
///
public JsonValueChange Change
{
get { return change; }
}
///
/// Gets the index in the where the change happened, or
/// -1 if the change happened in a of a different type.
///
public int Index
{
get { return index; }
}
///
/// Gets the key in the where the change happened, or
/// null if the change happened in a of a different type.
///
/// This property can also be null if the event type is
/// Clear.
public string Key
{
get { return key; }
}
}
}