/// <summary> /// Sets the value of a specific property in the context. /// </summary> /// <param name="prop">Property to set.</param> /// <param name="value">Value for the property.</param> /// <remarks> /// Context properties are used to control the behaviour of encoding and decoding. /// </remarks> /// <exception cref="ArgumentOutOfRangeException">Thrown if the value is rejected by the <see cref="FudgeContextProperty"/> as invalid.</exception> public void SetProperty(FudgeContextProperty prop, object value) { if (prop == null) { throw new ArgumentNullException("prop"); } if (!prop.IsValidValue(value)) { throw new ArgumentOutOfRangeException("Value is not valid for context property " + prop.Name); } int index = prop.Index; if (index >= properties.Length) { lock (this) { if (index >= properties.Length) { int newSize = Math.Max(properties.Length, FudgeContextProperty.MaxIndex + 1); var newArray = new object[newSize]; properties.CopyTo(newArray, 0); properties = newArray; } } } properties[index] = value; }
/// <summary> /// Sets the value of a specific property in the context. /// </summary> /// <param name="prop">Property to set.</param> /// <param name="value">Value for the property.</param> /// <remarks> /// Context properties are used to control the behaviour of encoding and decoding. /// </remarks> /// <exception cref="ArgumentOutOfRangeException">Thrown if the value is rejected by the <see cref="FudgeContextProperty"/> as invalid.</exception> public void SetProperty(FudgeContextProperty prop, object value) { if (prop == null) throw new ArgumentNullException("prop"); if (!prop.IsValidValue(value)) throw new ArgumentOutOfRangeException("Value is not valid for context property " + prop.Name); int index = prop.Index; if (index >= properties.Length) { lock (this) { if (index >= properties.Length) { int newSize = Math.Max(properties.Length, FudgeContextProperty.MaxIndex + 1); var newArray = new object[newSize]; properties.CopyTo(newArray, 0); properties = newArray; } } } properties[index] = value; }