本文整理汇总了C#中Optional.WithDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Optional.WithDefault方法的具体用法?C# Optional.WithDefault怎么用?C# Optional.WithDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Optional
的用法示例。
在下文中一共展示了Optional.WithDefault方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ServerSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="ServerSettings"/> class.
/// </summary>
/// <param name="heartbeatInterval">The heartbeat interval.</param>
/// <param name="heartbeatTimeout">The heartbeat timeout.</param>
public ServerSettings(
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
Optional<TimeSpan> heartbeatTimeout = default(Optional<TimeSpan>))
{
_heartbeatInterval = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(heartbeatInterval.WithDefault(DefaultHeartbeatInterval), "heartbeatInterval");
_heartbeatTimeout = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(heartbeatTimeout.WithDefault(DefaultHeartbeatTimeout), "heartbeatTimeout");
}
示例2: With
// methods
/// <summary>
/// Returns a new ServerSettings instance with some settings changed.
/// </summary>
/// <param name="heartbeatInterval">The heartbeat interval.</param>
/// <param name="heartbeatTimeout">The heartbeat timeout.</param>
/// <returns>A new ServerSettings instance.</returns>
public ServerSettings With(
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
Optional<TimeSpan> heartbeatTimeout = default(Optional<TimeSpan>))
{
return new ServerSettings(
heartbeatInterval: heartbeatInterval.WithDefault(_heartbeatInterval),
heartbeatTimeout: heartbeatTimeout.WithDefault(_heartbeatTimeout));
}
示例3: ConnectionSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="ConnectionSettings"/> class.
/// </summary>
/// <param name="authenticators">The authenticators.</param>
/// <param name="maxIdleTime">The maximum idle time.</param>
/// <param name="maxLifeTime">The maximum life time.</param>
public ConnectionSettings(
Optional<IEnumerable<IAuthenticator>> authenticators = default(Optional<IEnumerable<IAuthenticator>>),
Optional<TimeSpan> maxIdleTime = default(Optional<TimeSpan>),
Optional<TimeSpan> maxLifeTime = default(Optional<TimeSpan>))
{
_authenticators = Ensure.IsNotNull(authenticators.WithDefault(__noAuthenticators), "authenticators").ToList();
_maxIdleTime = Ensure.IsGreaterThanZero(maxIdleTime.WithDefault(TimeSpan.FromMinutes(10)), "maxIdleTime");
_maxLifeTime = Ensure.IsGreaterThanZero(maxLifeTime.WithDefault(TimeSpan.FromMinutes(30)), "maxLifeTime");
}
示例4: ConnectionSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="ConnectionSettings" /> class.
/// </summary>
/// <param name="authenticators">The authenticators.</param>
/// <param name="maxIdleTime">The maximum idle time.</param>
/// <param name="maxLifeTime">The maximum life time.</param>
/// <param name="applicationName">The application name.</param>
public ConnectionSettings(
Optional<IEnumerable<IAuthenticator>> authenticators = default(Optional<IEnumerable<IAuthenticator>>),
Optional<TimeSpan> maxIdleTime = default(Optional<TimeSpan>),
Optional<TimeSpan> maxLifeTime = default(Optional<TimeSpan>),
Optional<string> applicationName = default(Optional<string>))
{
_authenticators = Ensure.IsNotNull(authenticators.WithDefault(__noAuthenticators), "authenticators").ToList();
_maxIdleTime = Ensure.IsGreaterThanZero(maxIdleTime.WithDefault(TimeSpan.FromMinutes(10)), "maxIdleTime");
_maxLifeTime = Ensure.IsGreaterThanZero(maxLifeTime.WithDefault(TimeSpan.FromMinutes(30)), "maxLifeTime");
_applicationName = ApplicationNameHelper.EnsureApplicationNameIsValid(applicationName.WithDefault(null), nameof(applicationName));
}
示例5: ConnectionPoolSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="ConnectionPoolSettings"/> class.
/// </summary>
/// <param name="maintenanceInterval">The maintenance interval.</param>
/// <param name="maxConnections">The maximum number of connections.</param>
/// <param name="minConnections">The minimum number of connections.</param>
/// <param name="waitQueueSize">Size of the wait queue.</param>
/// <param name="waitQueueTimeout">The wait queue timeout.</param>
public ConnectionPoolSettings(
Optional<TimeSpan> maintenanceInterval = default(Optional<TimeSpan>),
Optional<int> maxConnections = default(Optional<int>),
Optional<int> minConnections = default(Optional<int>),
Optional<int> waitQueueSize = default(Optional<int>),
Optional<TimeSpan> waitQueueTimeout = default(Optional<TimeSpan>))
{
_maintenanceInterval = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(maintenanceInterval.WithDefault(TimeSpan.FromMinutes(1)), "maintenanceInterval");
_maxConnections = Ensure.IsGreaterThanZero(maxConnections.WithDefault(100), "maxConnections");
_minConnections = Ensure.IsGreaterThanOrEqualToZero(minConnections.WithDefault(0), "minConnections");
_waitQueueSize = Ensure.IsGreaterThanOrEqualToZero(waitQueueSize.WithDefault(_maxConnections * 5), "waitQueueSize");
_waitQueueTimeout = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(waitQueueTimeout.WithDefault(TimeSpan.FromMinutes(2)), "waitQueueTimeout");
}
示例6: SslStreamSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="SslStreamSettings"/> class.
/// </summary>
/// <param name="checkCertificateRevocation">Whether to check for certificate revocation.</param>
/// <param name="clientCertificates">The client certificates.</param>
/// <param name="clientCertificateSelectionCallback">The client certificate selection callback.</param>
/// <param name="enabledProtocols">The enabled protocols.</param>
/// <param name="serverCertificateValidationCallback">The server certificate validation callback.</param>
public SslStreamSettings(
Optional<bool> checkCertificateRevocation = default(Optional<bool>),
Optional<IEnumerable<X509Certificate>> clientCertificates = default(Optional<IEnumerable<X509Certificate>>),
Optional<LocalCertificateSelectionCallback> clientCertificateSelectionCallback = default(Optional<LocalCertificateSelectionCallback>),
Optional<SslProtocols> enabledProtocols = default(Optional<SslProtocols>),
Optional<RemoteCertificateValidationCallback> serverCertificateValidationCallback = default(Optional<RemoteCertificateValidationCallback>))
{
_checkCertificateRevocation = checkCertificateRevocation.WithDefault(true);
_clientCertificates = Ensure.IsNotNull(clientCertificates.WithDefault(Enumerable.Empty<X509Certificate>()), "clientCertificates").ToList();
_clientCertificateSelectionCallback = clientCertificateSelectionCallback.WithDefault(null);
_enabledSslProtocols = enabledProtocols.WithDefault(SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls);
_serverCertificateValidationCallback = serverCertificateValidationCallback.WithDefault(null);
}
示例7: TcpStreamSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="TcpStreamSettings"/> class.
/// </summary>
/// <param name="addressFamily">The address family.</param>
/// <param name="connectTimeout">The connect timeout.</param>
/// <param name="readTimeout">The read timeout.</param>
/// <param name="receiveBufferSize">Size of the receive buffer.</param>
/// <param name="sendBufferSize">Size of the send buffer.</param>
/// <param name="socketConfigurator">The socket configurator.</param>
/// <param name="writeTimeout">The write timeout.</param>
public TcpStreamSettings(
Optional<AddressFamily> addressFamily = default(Optional<AddressFamily>),
Optional<TimeSpan> connectTimeout = default(Optional<TimeSpan>),
Optional<TimeSpan?> readTimeout = default(Optional<TimeSpan?>),
Optional<int> receiveBufferSize = default(Optional<int>),
Optional<int> sendBufferSize = default(Optional<int>),
Optional<Action<Socket>> socketConfigurator = default(Optional<Action<Socket>>),
Optional<TimeSpan?> writeTimeout = default(Optional<TimeSpan?>))
{
_addressFamily = addressFamily.WithDefault(AddressFamily.InterNetwork);
_connectTimeout = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(connectTimeout.WithDefault(Timeout.InfiniteTimeSpan), "connectTimeout");
_readTimeout = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(readTimeout.WithDefault(null), "readTimeout");
_receiveBufferSize = Ensure.IsGreaterThanZero(receiveBufferSize.WithDefault(64 * 1024), "receiveBufferSize");
_sendBufferSize = Ensure.IsGreaterThanZero(sendBufferSize.WithDefault(64 * 1024), "sendBufferSize");
_socketConfigurator = socketConfigurator.WithDefault(null);
_writeTimeout = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(writeTimeout.WithDefault(null), "writeTimeout");
}
示例8: ClusterSettings
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="ClusterSettings"/> class.
/// </summary>
/// <param name="connectionMode">The connection mode.</param>
/// <param name="endPoints">The end points.</param>
/// <param name="maxServerSelectionWaitQueueSize">Maximum size of the server selection wait queue.</param>
/// <param name="replicaSetName">Name of the replica set.</param>
/// <param name="serverSelectionTimeout">The server selection timeout.</param>
/// <param name="preServerSelector">The pre server selector.</param>
/// <param name="postServerSelector">The post server selector.</param>
public ClusterSettings(
Optional<ClusterConnectionMode> connectionMode = default(Optional<ClusterConnectionMode>),
Optional<IEnumerable<EndPoint>> endPoints = default(Optional<IEnumerable<EndPoint>>),
Optional<int> maxServerSelectionWaitQueueSize = default(Optional<int>),
Optional<string> replicaSetName = default(Optional<string>),
Optional<TimeSpan> serverSelectionTimeout = default(Optional<TimeSpan>),
Optional<IServerSelector> preServerSelector = default(Optional<IServerSelector>),
Optional<IServerSelector> postServerSelector = default(Optional<IServerSelector>))
{
_connectionMode = connectionMode.WithDefault(ClusterConnectionMode.Automatic);
_endPoints = Ensure.IsNotNull(endPoints.WithDefault(__defaultEndPoints), "endPoints").ToList();
_maxServerSelectionWaitQueueSize = Ensure.IsGreaterThanOrEqualToZero(maxServerSelectionWaitQueueSize.WithDefault(500), "maxServerSelectionWaitQueueSize");
_replicaSetName = replicaSetName.WithDefault(null);
_serverSelectionTimeout = Ensure.IsGreaterThanOrEqualToZero(serverSelectionTimeout.WithDefault(TimeSpan.FromSeconds(30)), "serverSelectionTimeout");
_preServerSelector = preServerSelector.WithDefault(null);
_postServerSelector = postServerSelector.WithDefault(null);
}
示例9: With
// methods
/// <summary>
/// Returns a new TcpStreamSettings instance with some settings changed.
/// </summary>
/// <param name="addressFamily">The address family.</param>
/// <param name="connectTimeout">The connect timeout.</param>
/// <param name="readTimeout">The read timeout.</param>
/// <param name="receiveBufferSize">Size of the receive buffer.</param>
/// <param name="sendBufferSize">Size of the send buffer.</param>
/// <param name="socketConfigurator">The socket configurator.</param>
/// <param name="writeTimeout">The write timeout.</param>
/// <returns>A new TcpStreamSettings instance.</returns>
public TcpStreamSettings With(
Optional<AddressFamily> addressFamily = default(Optional<AddressFamily>),
Optional<TimeSpan> connectTimeout = default(Optional<TimeSpan>),
Optional<TimeSpan?> readTimeout = default(Optional<TimeSpan?>),
Optional<int> receiveBufferSize = default(Optional<int>),
Optional<int> sendBufferSize = default(Optional<int>),
Optional<Action<Socket>> socketConfigurator = default(Optional<Action<Socket>>),
Optional<TimeSpan?> writeTimeout = default(Optional<TimeSpan?>))
{
return new TcpStreamSettings(
addressFamily: addressFamily.WithDefault(_addressFamily),
connectTimeout: connectTimeout.WithDefault(_connectTimeout),
readTimeout: readTimeout.WithDefault(_readTimeout),
receiveBufferSize: receiveBufferSize.WithDefault(_receiveBufferSize),
sendBufferSize: sendBufferSize.WithDefault(_sendBufferSize),
socketConfigurator: socketConfigurator.WithDefault(_socketConfigurator),
writeTimeout: writeTimeout.WithDefault(_writeTimeout));
}
示例10: With
// methods
/// <summary>
/// Returns a new ClusterSettings instance with some settings changed.
/// </summary>
/// <param name="connectionMode">The connection mode.</param>
/// <param name="endPoints">The end points.</param>
/// <param name="maxServerSelectionWaitQueueSize">Maximum size of the server selection wait queue.</param>
/// <param name="replicaSetName">Name of the replica set.</param>
/// <param name="serverSelectionTimeout">The server selection timeout.</param>
/// <param name="preServerSelector">The pre server selector.</param>
/// <param name="postServerSelector">The post server selector.</param>
/// <returns>A new ClusterSettings instance.</returns>
public ClusterSettings With(
Optional<ClusterConnectionMode> connectionMode = default(Optional<ClusterConnectionMode>),
Optional<IEnumerable<EndPoint>> endPoints = default(Optional<IEnumerable<EndPoint>>),
Optional<int> maxServerSelectionWaitQueueSize = default(Optional<int>),
Optional<string> replicaSetName = default(Optional<string>),
Optional<TimeSpan> serverSelectionTimeout = default(Optional<TimeSpan>),
Optional<IServerSelector> preServerSelector = default(Optional<IServerSelector>),
Optional<IServerSelector> postServerSelector = default(Optional<IServerSelector>))
{
return new ClusterSettings(
connectionMode: connectionMode.WithDefault(_connectionMode),
endPoints: Optional.Enumerable(endPoints.WithDefault(_endPoints)),
maxServerSelectionWaitQueueSize: maxServerSelectionWaitQueueSize.WithDefault(_maxServerSelectionWaitQueueSize),
replicaSetName: replicaSetName.WithDefault(_replicaSetName),
serverSelectionTimeout: serverSelectionTimeout.WithDefault(_serverSelectionTimeout),
preServerSelector: Optional.Create(preServerSelector.WithDefault(_preServerSelector)),
postServerSelector: Optional.Create(postServerSelector.WithDefault(_postServerSelector)));
}
示例11: CreateSubject
// private methods
private AsyncCursor<BsonDocument> CreateSubject(
Optional<IChannelSource> channelSource = default(Optional<IChannelSource>),
Optional<CollectionNamespace> collectionNamespace = default(Optional<CollectionNamespace>),
Optional<IBsonSerializer<BsonDocument>> serializer = default(Optional<IBsonSerializer<BsonDocument>>),
Optional<BsonDocument> query = default(Optional<BsonDocument>),
Optional<IReadOnlyList<BsonDocument>> firstBatch = default(Optional<IReadOnlyList<BsonDocument>>),
Optional<long> cursorId = default(Optional<long>),
Optional<int?> batchSize = default(Optional<int?>),
Optional<int?> limit = default(Optional<int?>),
Optional<TimeSpan?> maxTime = default(Optional<TimeSpan?>))
{
return new AsyncCursor<BsonDocument>(
channelSource.WithDefault(Substitute.For<IChannelSource>()),
collectionNamespace.WithDefault(new CollectionNamespace("test", "test")),
query.WithDefault(new BsonDocument()),
firstBatch.WithDefault(new List<BsonDocument>()),
cursorId.WithDefault(0),
batchSize.WithDefault(null),
limit.WithDefault(null),
serializer.WithDefault(BsonDocumentSerializer.Instance),
new MessageEncoderSettings(),
maxTime.WithDefault(null));
}
示例12: With
// methods
/// <summary>
/// Returns a new ConnectionSettings instance with some settings changed.
/// </summary>
/// <param name="authenticators">The authenticators.</param>
/// <param name="maxIdleTime">The maximum idle time.</param>
/// <param name="maxLifeTime">The maximum life time.</param>
/// <returns>A new ConnectionSettings instance.</returns>
public ConnectionSettings With(
Optional<IEnumerable<IAuthenticator>> authenticators = default(Optional<IEnumerable<IAuthenticator>>),
Optional<TimeSpan> maxIdleTime = default(Optional<TimeSpan>),
Optional<TimeSpan> maxLifeTime = default(Optional<TimeSpan>))
{
return new ConnectionSettings(
authenticators: Optional.Enumerable(authenticators.WithDefault(_authenticators)),
maxIdleTime: maxIdleTime.WithDefault(_maxIdleTime),
maxLifeTime: maxLifeTime.WithDefault(_maxLifeTime));
}
示例13: With
// methods
/// <summary>
/// Returns a new ConnectionPoolSettings instance with some settings changed.
/// </summary>
/// <param name="maintenanceInterval">The maintenance interval.</param>
/// <param name="maxConnections">The maximum connections.</param>
/// <param name="minConnections">The minimum connections.</param>
/// <param name="waitQueueSize">Size of the wait queue.</param>
/// <param name="waitQueueTimeout">The wait queue timeout.</param>
/// <returns>A new ConnectionPoolSettings instance.</returns>
public ConnectionPoolSettings With (
Optional<TimeSpan> maintenanceInterval = default(Optional<TimeSpan>),
Optional<int> maxConnections = default(Optional<int>),
Optional<int> minConnections = default(Optional<int>),
Optional<int> waitQueueSize = default(Optional<int>),
Optional<TimeSpan> waitQueueTimeout = default(Optional<TimeSpan>))
{
return new ConnectionPoolSettings(
maintenanceInterval: maintenanceInterval.WithDefault(_maintenanceInterval),
maxConnections: maxConnections.WithDefault(_maxConnections),
minConnections: minConnections.WithDefault(_minConnections),
waitQueueSize: waitQueueSize.WithDefault(_waitQueueSize),
waitQueueTimeout: waitQueueTimeout.WithDefault(_waitQueueTimeout));
}