void LoadDatabase(LSDatabase database)
        {
            _database = database;
            bool isValid = false;

            if (_database != null)
            {
                if (database.GetType() != DatabaseType)
                {
                    //Note: A hacky fix for changing the type of a previously saved database is to turn on Debug mode
                    //and change the script type of the database asset in the inspector. Back it up before attempting!
                }
                DatabaseEditor = new EditorLSDatabase();
                DatabaseEditor.Initialize(this, Database, out isValid);
            }
            if (!isValid)
            {
                Debug.Log("Load unsuccesful");
                this.DatabaseEditor = null;
                this._database      = null;
                IsLoaded            = false;
                return;
            }
            LSFSettingsManager.GetSettings().Database = database;
            LSFSettingsModifier.Save();
            IsLoaded = true;
        }
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataFieldName,
            SortInfo[] sorts,
            out bool valid)
        {
            Sorts = sorts;
            this.TargetType = targetType;
            SourceEditor = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase = sourceDatabase;
            _dataFieldName = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (info == null) {
                Debug.Log (string.Format ("Field with fieldName of {0} not found.", dataFieldName));
                valid = false;
                return;
            }

            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
                Data = (DataItem[])Array.CreateInstance (TargetType,0);
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof (DataItemAttribute));
            _dataAttribute = dataAttribute ?? new DataItemAttribute ();
            valid = true;
        }
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataCodeName,
            string dataFieldName,
            SortInfo[] sorts)
        {
            Sorts            = sorts;
            this.TargetType  = targetType;
            SourceEditor     = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase   = sourceDatabase;
            DataCodeName     = dataCodeName;
            _dataFieldName   = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
            {
                Data = (DataItem[])Array.CreateInstance(TargetType, 0);
            }
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof(DataItemAttribute));

            _dataAttribute = dataAttribute ?? new DataItemAttribute();
        }
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataCodeName,
            string dataFieldName,
            SortInfo[] sorts)
        {
            Sorts = sorts;
            this.TargetType = targetType;
            SourceEditor = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase = sourceDatabase;
            DataCodeName = dataCodeName;
            _dataFieldName = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
                Data = (DataItem[])Array.CreateInstance (TargetType,0);
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof (DataItemAttribute));
            _dataAttribute = dataAttribute ?? new DataItemAttribute ();
        }
        public DataHelper(
            Type targetType,
            EditorLSDatabase sourceEditor,
            LSDatabase sourceDatabase,
            string displayName,
            string dataFieldName,
            SortInfo[] sorts,
            out bool valid)
        {
            Sorts            = sorts;
            this.TargetType  = targetType;
            SourceEditor     = sourceEditor;
            this.DisplayName = displayName;
            SourceDatabase   = sourceDatabase;
            _dataFieldName   = dataFieldName;

            FieldInfo info = sourceDatabase.GetType().GetField(_dataFieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (info == null)
            {
                Debug.Log(string.Format("Field with fieldName of {0} not found.", dataFieldName));
                valid = false;
                return;
            }

            _getData = () => (DataItem[])info.GetValue(sourceDatabase);
            _setData = (value) => info.SetValue(sourceDatabase, value);
            if (Data == null)
            {
                Data = (DataItem[])Array.CreateInstance(TargetType, 0);
            }
            DataItemAttribute dataAttribute = (DataItemAttribute)Attribute.GetCustomAttribute(targetType, typeof(DataItemAttribute));

            _dataAttribute = dataAttribute ?? new DataItemAttribute();
            valid          = true;
        }