Skip to content

Commit e8e9991

Browse files
committed
Removed parameter validation for private methods
Given C# 8.0's null reference types, there's no need to validate that non-nullable parameters of `private` methods are, in fact, not `null`. Those scenarios will trigger a warning from the compilere if there's a chance that they might be true. That said, if they are using values that are being sourced from external locations (either parameters or public methods or service calls) then those values should still be validated at their source.
1 parent adcf6a1 commit e8e9991

1 file changed

Lines changed: 1 addition & 49 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public SqlTopicRepository(string connectionString) : base() {
5757
/*------------------------------------------------------------------------------------------------------------------------
5858
| Set private fields
5959
\-----------------------------------------------------------------------------------------------------------------------*/
60-
_connectionString = connectionString;
60+
_connectionString = connectionString;
6161

6262
}
6363

@@ -66,12 +66,6 @@ public SqlTopicRepository(string connectionString) : base() {
6666
\-------------------------------------------------------------------------------------------------------------------------*/
6767
private static void AddTopic(SqlDataReader reader, Dictionary<int, Topic> topics) {
6868

69-
/*------------------------------------------------------------------------------------------------------------------------
70-
| Validate parameters
71-
\-----------------------------------------------------------------------------------------------------------------------*/
72-
Contract.Requires(reader, nameof(reader));
73-
Contract.Requires(topics, nameof(topics));
74-
7569
/*------------------------------------------------------------------------------------------------------------------------
7670
| Identify attributes
7771
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -101,12 +95,6 @@ private static void AddTopic(SqlDataReader reader, Dictionary<int, Topic> topics
10195
\-------------------------------------------------------------------------------------------------------------------------*/
10296
private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, Topic> topics) {
10397

104-
/*------------------------------------------------------------------------------------------------------------------------
105-
| Validate parameters
106-
\-----------------------------------------------------------------------------------------------------------------------*/
107-
Contract.Requires(reader, nameof(reader));
108-
Contract.Requires(topics, nameof(topics));
109-
11098
/*------------------------------------------------------------------------------------------------------------------------
11199
| Identify attributes
112100
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -158,12 +146,6 @@ private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, T
158146
/// <param name="topics">The index of topics currently being loaded.</param>
159147
private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int, Topic> topics) {
160148

161-
/*------------------------------------------------------------------------------------------------------------------------
162-
| Validate parameters
163-
\-----------------------------------------------------------------------------------------------------------------------*/
164-
Contract.Requires(topics, "The topics Dictionary must not be null.");
165-
Contract.Requires(reader, nameof(reader));
166-
167149
/*------------------------------------------------------------------------------------------------------------------------
168150
| Identify attributes
169151
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -240,12 +222,6 @@ private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int,
240222
/// <param name="topics">The index of topics currently being loaded.</param>
241223
private static void SetRelationships(SqlDataReader reader, Dictionary<int, Topic> topics) {
242224

243-
/*------------------------------------------------------------------------------------------------------------------------
244-
| Validate input
245-
\-----------------------------------------------------------------------------------------------------------------------*/
246-
Contract.Requires(topics, "The topics Dictionary must not be null.");
247-
Contract.Requires(reader, "The reader must not be null.");
248-
249225
/*------------------------------------------------------------------------------------------------------------------------
250226
| Identify attributes
251227
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -288,11 +264,6 @@ private static void SetRelationships(SqlDataReader reader, Dictionary<int, Topic
288264
/// <param name="topics">The index of topics currently being loaded.</param>
289265
private static void SetDerivedTopics(Dictionary<int, Topic> topics) {
290266

291-
/*------------------------------------------------------------------------------------------------------------------------
292-
| Validate input
293-
\-----------------------------------------------------------------------------------------------------------------------*/
294-
Contract.Requires(topics, "The topics Dictionary must not be null.");
295-
296267
/*------------------------------------------------------------------------------------------------------------------------
297268
| Loop through topics
298269
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -322,11 +293,6 @@ private static void SetDerivedTopics(Dictionary<int, Topic> topics) {
322293
/// <param name="topics">The index of topics currently being loaded.</param>
323294
private static void SetVersionHistory(SqlDataReader reader, Dictionary<int, Topic> topics) {
324295

325-
/*------------------------------------------------------------------------------------------------------------------------
326-
| Validate input
327-
\-----------------------------------------------------------------------------------------------------------------------*/
328-
Contract.Requires(topics, "The topics Dictionary must not be null.");
329-
330296
/*------------------------------------------------------------------------------------------------------------------------
331297
| Identify attributes
332298
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -1022,14 +988,8 @@ public override void Delete(Topic topic, bool isRecursive = false) {
1022988
/// An XML-formatted string representing the <see cref="Topic.Relationships"/> XML content, or a blank string if
1023989
/// <c>skipXml == true</c>.
1024990
/// </returns>
1025-
/// <requires description="The topic must not be null." exception="T:System.ArgumentNullException">topic != null</requires>
1026991
private static string PersistRelations(Topic topic, SqlConnection connection, bool skipXml) {
1027992

1028-
/*------------------------------------------------------------------------------------------------------------------------
1029-
| Validate input
1030-
\-----------------------------------------------------------------------------------------------------------------------*/
1031-
Contract.Requires(topic, "The topic must not be null.");
1032-
1033993
/*------------------------------------------------------------------------------------------------------------------------
1034994
| Return blank if the topic has no relations.
1035995
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -1111,14 +1071,8 @@ private static string PersistRelations(Topic topic, SqlConnection connection, bo
11111071
/// </summary>
11121072
/// <param name="topic">The topic object for which to create the relationships.</param>
11131073
/// <returns>The XML string.</returns>
1114-
/// <requires description="The topic must not be null." exception="T:System.ArgumentNullException">topic != null</requires>
11151074
private static string CreateRelationshipsXml(Topic topic) {
11161075

1117-
/*------------------------------------------------------------------------------------------------------------------------
1118-
| Validate input
1119-
\-----------------------------------------------------------------------------------------------------------------------*/
1120-
Contract.Requires(topic, "The topic must not be null.");
1121-
11221076
/*------------------------------------------------------------------------------------------------------------------------
11231077
| Create XML string container
11241078
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -1147,7 +1101,5 @@ private static string CreateRelationshipsXml(Topic topic) {
11471101
return attributesXml.ToString();
11481102
}
11491103

1150-
1151-
11521104
} //Class
11531105
} //Namespace

0 commit comments

Comments
 (0)