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)); }
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); }
public virtual void SetValue(SQLiteLoadOptions options, object obj, object value) { if (SetValueAction == null) { throw new InvalidOperationException(); } options = options ?? Table.Database.CreateLoadOptions(); if (options == null) { throw new InvalidOperationException(); } bool raiseOnErrorsChanged = false; bool raiseOnPropertyChanging = false; bool raiseOnPropertyChanged = false; ISQLiteObjectChangeEvents ce = null; if (options.ObjectChangeEventsDisabled) { ce = obj as ISQLiteObjectChangeEvents; if (ce != null) { raiseOnErrorsChanged = ce.RaiseOnErrorsChanged; raiseOnPropertyChanging = ce.RaiseOnPropertyChanging; raiseOnPropertyChanged = ce.RaiseOnPropertyChanged; ce.RaiseOnErrorsChanged = false; ce.RaiseOnPropertyChanging = false; ce.RaiseOnPropertyChanged = false; } } try { SetValueAction(options, obj, value); } finally { if (ce != null) { ce.RaiseOnErrorsChanged = raiseOnErrorsChanged; ce.RaiseOnPropertyChanging = raiseOnPropertyChanging; ce.RaiseOnPropertyChanged = raiseOnPropertyChanged; } } }
public virtual void SetPrimaryKey(SQLiteLoadOptions options, object instance, object[] primaryKey) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (primaryKey == null) { throw new ArgumentNullException(nameof(primaryKey)); } var pkCols = PrimaryKeyColumns.ToList(); if (pkCols.Count != primaryKey.Length) { throw new ArgumentException(null, nameof(primaryKey)); } for (int i = 0; i < primaryKey.Length; i++) { pkCols[i].SetValue(options, instance, primaryKey[i]); } }
public object GetInstance(Type type, SQLiteLoadOptions options) => GetInstance(type, null, options);