From c5fddfa4224bf418ebbceb1c281e37337407d6fc Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Sun, 15 Jul 2018 12:35:38 -0400 Subject: [PATCH] Add some doc comments, align styles (#520) --- .../NpgsqlDbContextOptionsExtensions.cs | 61 +++++++++++++------ 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlDbContextOptionsExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlDbContextOptionsExtensions.cs index a2cda740d..d0b359e04 100644 --- a/src/EFCore.PG/Extensions/NpgsqlDbContextOptionsExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlDbContextOptionsExtensions.cs @@ -1,4 +1,5 @@ #region License + // The PostgreSQL License // // Copyright (C) 2016 The Npgsql Development Team @@ -19,6 +20,7 @@ // AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS // ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS // TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + #endregion using System; @@ -32,15 +34,22 @@ // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { + /// + /// Provides extension methods on and + /// used to configure a to context to a PostgreSQL database with Npgsql. + /// public static class NpgsqlDbContextOptionsExtensions { /// - /// Configures the context to connect to a PostgreSQL database with Npgsql. + /// Configures the context to connect to a PostgreSQL database with Npgsql. /// /// A builder for setting options on the context. /// The connection string of the database to connect to. /// An optional action to allow additional Npgsql-specific configuration. - /// The options builder so that further configuration can be chained. + /// + /// The options builder so that further configuration can be chained. + /// + [NotNull] public static DbContextOptionsBuilder UseNpgsql( [NotNull] this DbContextOptionsBuilder optionsBuilder, [NotNull] string connectionString, @@ -58,16 +67,19 @@ public static DbContextOptionsBuilder UseNpgsql( } /// - /// Configures the context to connect to a PostgreSQL database with Npgsql. + /// Configures the context to connect to a PostgreSQL database with Npgsql. /// /// A builder for setting options on the context. /// - /// An existing to be used to connect to the database. If the connection is - /// in the open state then EF will not open or close the connection. If the connection is in the closed - /// state then EF will open and close the connection as needed. + /// An existing to be used to connect to the database. If the connection is + /// in the open state then EF will not open or close the connection. If the connection is in the closed + /// state then EF will open and close the connection as needed. /// /// An optional action to allow additional Npgsql-specific configuration. - /// The options builder so that further configuration can be chained. + /// + /// The options builder so that further configuration can be chained. + /// + [NotNull] public static DbContextOptionsBuilder UseNpgsql( [NotNull] this DbContextOptionsBuilder optionsBuilder, [NotNull] DbConnection connection, @@ -85,12 +97,15 @@ public static DbContextOptionsBuilder UseNpgsql( } /// - /// Configures the context to connect to a PostgreSQL database with Npgsql. + /// Configures the context to connect to a PostgreSQL database with Npgsql. /// /// A builder for setting options on the context. /// The connection string of the database to connect to. /// An optional action to allow additional Npgsql-configuration. - /// The options builder so that further configuration can be chained. + /// + /// The options builder so that further configuration can be chained. + /// + [NotNull] public static DbContextOptionsBuilder UseNpgsql( [NotNull] this DbContextOptionsBuilder optionsBuilder, [NotNull] string connectionString, @@ -100,16 +115,19 @@ public static DbContextOptionsBuilder UseNpgsql( (DbContextOptionsBuilder)optionsBuilder, connectionString, npgsqlOptionsAction); /// - /// Configures the context to connect to a PostgreSQL database with Npgsql. + /// Configures the context to connect to a PostgreSQL database with Npgsql. /// /// A builder for setting options on the context. /// - /// An existing to be used to connect to the database. If the connection is - /// in the open state then EF will not open or close the connection. If the connection is in the closed - /// state then EF will open and close the connection as needed. + /// An existing to be used to connect to the database. If the connection is + /// in the open state then EF will not open or close the connection. If the connection is in the closed + /// state then EF will open and close the connection as needed. /// /// An optional action to allow additional Npgsql-specific configuration. - /// The options builder so that further configuration can be chained. + /// + /// The options builder so that further configuration can be chained. + /// + [NotNull] public static DbContextOptionsBuilder UseNpgsql( [NotNull] this DbContextOptionsBuilder optionsBuilder, [NotNull] DbConnection connection, @@ -118,12 +136,17 @@ public static DbContextOptionsBuilder UseNpgsql( => (DbContextOptionsBuilder)UseNpgsql( (DbContextOptionsBuilder)optionsBuilder, connection, npgsqlOptionsAction); - private static NpgsqlOptionsExtension GetOrCreateExtension(DbContextOptionsBuilder optionsBuilder) - { - var existing = optionsBuilder.Options.FindExtension(); - return existing != null + /// + /// Returns an existing instance of , or a new instance if one does not exist. + /// + /// The to search. + /// + /// An existing instance of , or a new instance if one does not exist. + /// + [NotNull] + private static NpgsqlOptionsExtension GetOrCreateExtension([NotNull] DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.Options.FindExtension() is NpgsqlOptionsExtension existing ? new NpgsqlOptionsExtension(existing) : new NpgsqlOptionsExtension(); - } } }