コード例 #1
0
        public virtual T GetInstance <T>(SQLiteStatement statement, SQLiteLoadOptions options)
        {
            if (options?.GetInstanceFunc != null)
            {
                return((T)options.GetInstanceFunc(typeof(T), statement, options));
            }

            return((T)GetInstance(typeof(T), statement, options));
        }
コード例 #2
0
        public virtual object GetInstance(Type type, SQLiteStatement statement, SQLiteLoadOptions options)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            object instance;

            if (options?.GetInstanceFunc != null)
            {
                instance = options.GetInstanceFunc(type, statement, options);
            }
            else
            {
                instance = null;
                if (typeof(ISQLiteObject).IsAssignableFrom(type))
                {
                    try
                    {
                        instance = Activator.CreateInstance(type, Database);
                    }
                    catch
                    {
                        // do nothing
                    }
                }

                if (instance == null)
                {
                    try
                    {
                        instance = Activator.CreateInstance(type);
                    }
                    catch (Exception e)
                    {
                        throw new SqlNadoException("0011: Cannot create an instance for the '" + Name + "' table.", e);
                    }
                }
            }

            if (instance is ISQLiteObject so)
            {
                if (so.Database == null)
                {
                    so.Database = Database;
                }
            }
            InitializeAutomaticColumns(instance);
            return(instance);
        }