internal void ReadProperty(RecordReader reader) { ushort propertyNameLength = reader.ReadUInt16(); Name = reader.ReadStringFixedLength(propertyNameLength); Type = (ScriptPropertyType)reader.ReadByte(); state = (ScriptPropertyState)reader.ReadByte(); if (!propertyTypeMap.ContainsKey(Type)) { throw new InvalidDataException("Unexpected script property type: " + Type); } var instanceType = propertyTypeMap[Type]; value = ReadValue(reader, instanceType); }
private void DoSetValue(object value, int?index) { var array = value as Array; if (index.HasValue) { // Make sure value is an array if (array == null) { throw new ArgumentException("Index must not be specified when assigning value to a script property that is not an array (ArrayOf)."); } if (index.Value == -1) { // Append at the end // New array is created and the old array is copied into the new array var newArray = Array.CreateInstance(array.GetType().GetElementType(), array.Length + 1); Array.Copy(array, newArray, array.Length); newArray.SetValue(value, array.Length); value = newArray; } else { // Set existing array property array.SetValue(value, index.Value); } } else { // Make sure value is not an array if (array != null) { throw new ArgumentException("To assign value to a script property that is an array (ArrayOf) the index must be specified."); } // Scalar property this.value = value; } state = ScriptPropertyState.Edited; }
public void ResetValue() { state = ScriptPropertyState.Removed; }