using System; using System.Runtime.CompilerServices; namespace BansheeEngine { #pragma warning disable 649 /// /// Allows you to access meta-data about a managed array and its children. Similar to Reflection but simpler and faster. /// public sealed class SerializableArray : ScriptObject { private SerializableProperty.FieldType elementType; private Type internalElementType; private SerializableProperty parentProperty; /// /// Type of elements stored in the array. /// public SerializableProperty.FieldType ElementType { get { return elementType; } } /// /// Constructor for use by the runtime only. /// /// C# type of the elements in the array. /// Property used for retrieving this entry. private SerializableArray(Type internalElementType, SerializableProperty parentProperty) { this.parentProperty = parentProperty; this.internalElementType = internalElementType; elementType = SerializableProperty.DetermineFieldType(internalElementType); } /// /// Returns a serializable property for a specific array element. /// /// Index of the element in the array. /// Serializable property that allows you to manipulate contents of the array entry. 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; } /// /// Returns number of elements in the array. /// /// Number of elements in the array. 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); } }