Skip to content

Commit 3a97459

Browse files
committed
Added Optional.Enumerable helper method.
1 parent 97e125c commit 3a97459

File tree

11 files changed

+24
-13
lines changed

11 files changed

+24
-13
lines changed

src/MongoDB.Driver.Core.Tests/Specifications/server-discovery-and-monitoring/TestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private ICluster BuildCluster(BsonDocument definition)
175175
{
176176
var connectionString = new ConnectionString((string)definition["uri"]);
177177
var settings = new ClusterSettings(
178-
endPoints: Optional.Create<IEnumerable<EndPoint>>(connectionString.Hosts),
178+
endPoints: Optional.Enumerable(connectionString.Hosts),
179179
connectionMode: connectionString.Connect,
180180
replicaSetName: connectionString.ReplicaSet);
181181

src/MongoDB.Driver.Core.Tests/Specifications/server-selection/ServerSelectionTestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private ReadPreference BuildReadPreference(BsonDocument readPreferenceDescriptio
9999
throw new NotSupportedException("Unknown read preference mode: " + readPreferenceDescription["mode"]);
100100
}
101101

102-
return readPreference.With(tagSets: Optional.Create(tagSets));
102+
return readPreference.With(tagSets: Optional.Enumerable(tagSets));
103103
}
104104

105105
private ClusterDescription BuildClusterDescription(BsonDocument topologyDescription)

src/MongoDB.Driver.Core/Core/Configuration/ClusterBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static ClusterBuilder ConfigureWithConnectionString(this ClusterBuilder b
134134
// Cluster
135135
if (connectionString.Hosts.Count > 0)
136136
{
137-
builder = builder.ConfigureCluster(s => s.With(endPoints: Optional.Create<IEnumerable<EndPoint>>(connectionString.Hosts)));
137+
builder = builder.ConfigureCluster(s => s.With(endPoints: Optional.Enumerable(connectionString.Hosts)));
138138
}
139139
if (connectionString.ReplicaSet != null)
140140
{

src/MongoDB.Driver.Core/Core/Configuration/ClusterSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public ClusterSettings With(
172172
{
173173
return new ClusterSettings(
174174
connectionMode: connectionMode.WithDefault(_connectionMode),
175-
endPoints: Optional.Create(endPoints.WithDefault(_endPoints)),
175+
endPoints: Optional.Enumerable(endPoints.WithDefault(_endPoints)),
176176
maxServerSelectionWaitQueueSize: maxServerSelectionWaitQueueSize.WithDefault(_maxServerSelectionWaitQueueSize),
177177
replicaSetName: replicaSetName.WithDefault(_replicaSetName),
178178
serverSelectionTimeout: serverSelectionTimeout.WithDefault(_serverSelectionTimeout),

src/MongoDB.Driver.Core/Core/Configuration/ConnectionSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public ConnectionSettings With(
101101
Optional<TimeSpan> maxLifeTime = default(Optional<TimeSpan>))
102102
{
103103
return new ConnectionSettings(
104-
authenticators: Optional.Create(authenticators.WithDefault(_authenticators)),
104+
authenticators: Optional.Enumerable(authenticators.WithDefault(_authenticators)),
105105
maxIdleTime: maxIdleTime.WithDefault(_maxIdleTime),
106106
maxLifeTime: maxLifeTime.WithDefault(_maxLifeTime));
107107
}

src/MongoDB.Driver.Core/Core/Configuration/SslStreamSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public SslStreamSettings With(
132132
{
133133
return new SslStreamSettings(
134134
checkCertificateRevocation: checkCertificateRevocation.WithDefault(_checkCertificateRevocation),
135-
clientCertificates: Optional.Create(clientCertificates.WithDefault(_clientCertificates)),
135+
clientCertificates: Optional.Enumerable(clientCertificates.WithDefault(_clientCertificates)),
136136
clientCertificateSelectionCallback: clientCertificateSelectionCallback.WithDefault(_clientCertificateSelectionCallback),
137137
enabledProtocols: enabledProtocols.WithDefault(_enabledSslProtocols),
138138
serverCertificateValidationCallback: serverCertificateValidationCallback.WithDefault(_serverCertificateValidationCallback));

src/MongoDB.Driver.Core/Core/Misc/Optional.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public static Optional<T> Create<T>(T value)
3939
{
4040
return new Optional<T>(value);
4141
}
42+
43+
/// <summary>
44+
/// Creates an instance of an optional parameter with an enumerable value.
45+
/// </summary>
46+
/// <typeparam name="TItem">The type of the items of the optional paramater.</typeparam>
47+
/// <param name="value">The value.</param>
48+
/// <returns>An instance of an optional parameter with an enumerable value.</returns>
49+
public static Optional<IEnumerable<TItem>> Enumerable<TItem>(IEnumerable<TItem> value)
50+
{
51+
return new Optional<IEnumerable<TItem>>(value);
52+
}
4253
}
4354

4455
/// <summary>

src/MongoDB.Driver.Core/ReadPreference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public ReadPreference With(
184184
{
185185
return new ReadPreference(
186186
mode.WithDefault(_mode),
187-
Optional.Create(tagSets.WithDefault(_tagSets)));
187+
Optional.Enumerable(tagSets.WithDefault(_tagSets)));
188188
}
189189
}
190190
}

src/MongoDB.Driver.Core/WriteConcern.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public WriteConcern(
125125
Optional<TimeSpan?> wTimeout = default(Optional<TimeSpan?>),
126126
Optional<bool?> fsync = default(Optional<bool?>),
127127
Optional<bool?> journal = default(Optional<bool?>))
128-
: this(new Optional<WValue>(Ensure.IsGreaterThanOrEqualToZero(w, "w")), wTimeout, fsync, journal)
128+
: this((WValue)Ensure.IsGreaterThanOrEqualToZero(w, "w"), wTimeout, fsync, journal)
129129
{
130130
}
131131

@@ -141,7 +141,7 @@ public WriteConcern(
141141
Optional<TimeSpan?> wTimeout = default(Optional<TimeSpan?>),
142142
Optional<bool?> fsync = default(Optional<bool?>),
143143
Optional<bool?> journal = default(Optional<bool?>))
144-
: this(new Optional<WValue>(Ensure.IsNotNullOrEmpty(mode, "mode")), wTimeout, fsync, journal)
144+
: this((WValue)Ensure.IsNotNullOrEmpty(mode, "mode"), wTimeout, fsync, journal)
145145
{
146146
}
147147

src/MongoDB.Driver/ClusterRegistry.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey cl
8282
var endPoints = clusterKey.Servers.Select(s => (EndPoint)new DnsEndPoint(s.Host, s.Port));
8383
return settings.With(
8484
connectionMode: clusterKey.ConnectionMode.ToCore(),
85-
endPoints: Optional.Create(endPoints),
85+
endPoints: Optional.Enumerable(endPoints),
8686
replicaSetName: clusterKey.ReplicaSetName,
8787
postServerSelector: new LatencyLimitingServerSelector(clusterKey.LocalThreshold));
8888
}
@@ -101,7 +101,7 @@ private ConnectionSettings ConfigureConnection(ConnectionSettings settings, Clus
101101
{
102102
var authenticators = clusterKey.Credentials.Select(c => c.ToAuthenticator());
103103
return settings.With(
104-
authenticators: Optional.Create(authenticators),
104+
authenticators: Optional.Enumerable(authenticators),
105105
maxIdleTime: clusterKey.MaxConnectionIdleTime,
106106
maxLifeTime: clusterKey.MaxConnectionLifeTime);
107107
}
@@ -126,7 +126,7 @@ private SslStreamSettings ConfigureSsl(SslStreamSettings settings, ClusterKey cl
126126
}
127127

128128
return settings.With(
129-
clientCertificates: Optional.Create(sslSettings.ClientCertificates ?? Enumerable.Empty<X509Certificate>()),
129+
clientCertificates: Optional.Enumerable(sslSettings.ClientCertificates ?? Enumerable.Empty<X509Certificate>()),
130130
checkCertificateRevocation: sslSettings.CheckCertificateRevocation,
131131
clientCertificateSelectionCallback: sslSettings.ClientCertificateSelectionCallback,
132132
enabledProtocols: sslSettings.EnabledSslProtocols,

0 commit comments

Comments
 (0)