protected CouchContext(CouchOptions options) { Check.NotNull(options, nameof(options)); var optionsBuilder = new CouchOptionsBuilder(options); var databaseBuilder = new CouchDatabaseBuilder(); #pragma warning disable CA2214 // Do not call overridable methods in constructors OnConfiguring(optionsBuilder); OnDatabaseCreating(databaseBuilder); #pragma warning restore CA2214 // Do not call overridable methods in constructors Client = new CouchClient(options); SetupDiscriminators(databaseBuilder); InitializeDatabases(options, databaseBuilder); }
protected CouchContext(CouchOptions options) { Check.NotNull(options, nameof(options)); var builder = new CouchOptionsBuilder(options); #pragma warning disable CA2214 // Do not call overridable methods in constructors OnConfiguring(builder); #pragma warning restore CA2214 // Do not call overridable methods in constructors Client = new CouchClient(options); PropertyInfo[] databasePropertyInfos = GetDatabaseProperties(); foreach (PropertyInfo propertyInfo in databasePropertyInfos) { Type documentType = propertyInfo.PropertyType.GetGenericArguments()[0]; object?database; if (options.CheckDatabaseExists) { MethodInfo getOrCreateDatabaseMethod = GetOrCreateDatabaseAsyncGenericMethod.MakeGenericMethod(documentType); #pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. var parameters = new[] { (object)null, null, default(CancellationToken) }; #pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. var task = (Task)getOrCreateDatabaseMethod.Invoke(Client, parameters); task.ConfigureAwait(false).GetAwaiter().GetResult(); PropertyInfo resultProperty = task.GetType().GetProperty(nameof(Task <object> .Result)); database = resultProperty.GetValue(task); } else { MethodInfo getDatabaseMethod = GetDatabaseGenericMethod.MakeGenericMethod(documentType); database = getDatabaseMethod.Invoke(Client, Array.Empty <object>()); } propertyInfo.SetValue(this, database); } }