using System; using System.Runtime.CompilerServices; namespace BansheeEngine { #pragma warning disable 649 public sealed class SerializableArray : ScriptObject { private SerializableProperty.FieldType elementType; private Type internalElementType; private SerializableProperty parentProperty; public SerializableProperty.FieldType ElementType { get { return elementType; } } // Constructed from native code private SerializableArray(Type internalElementType, SerializableProperty parentProperty) { this.parentProperty = parentProperty; this.internalElementType = internalElementType; elementType = SerializableProperty.DetermineFieldType(internalElementType); } public SerializableProperty GetProperty(int elementIdx) { SerializableProperty.Getter getter = () => { Array array = parentProperty.GetValue(); if (array != null) return array.GetValue(elementIdx); else return null; }; SerializableProperty.Setter setter = (object value) => { Array array = parentProperty.GetValue(); if(array != null) array.SetValue(value, elementIdx); }; SerializableProperty property = Internal_CreateProperty(mCachedPtr); property.Construct(ElementType, internalElementType, getter, setter); return property; } public int GetLength() { Array array = parentProperty.GetValue(); if (array != null) return array.GetLength(0); // TODO - Support multi-rank arrays else return 0; } [MethodImpl(MethodImplOptions.InternalCall)] private static extern SerializableProperty Internal_CreateProperty(IntPtr nativeInstance); } }