private void ParseOption(string name, string value) { switch (name.ToLowerInvariant()) { case "appname": string invalidApplicationNameMessage; if (!ApplicationNameHelper.IsApplicationNameValid(value, out invalidApplicationNameMessage)) { throw new MongoConfigurationException(invalidApplicationNameMessage); } _applicationName = value; break; case "authmechanism": _authMechanism = value; break; case "authmechanismproperties": foreach (var property in GetAuthMechanismProperties(name, value)) { _authMechanismProperties.Add(property.Key, property.Value); } break; case "authsource": _authSource = value; break; case "connect": _connect = ParseClusterConnectionMode(name, value); break; case "connecttimeout": case "connecttimeoutms": _connectTimeout = ParseTimeSpan(name, value); break; case "fsync": _fsync = ParseBoolean(name, value); break; case "gssapiservicename": _authMechanismProperties.Add("SERVICE_NAME", value); break; case "heartbeatfrequency": case "heartbeatfrequencyms": case "heartbeatinterval": case "heartbeatintervalms": _heartbeatInterval = ParseTimeSpan(name, value); break; case "heartbeattimeout": case "heartbeattimeoutms": _heartbeatTimeout = ParseTimeSpan(name, value); break; case "ipv6": _ipv6 = ParseBoolean(name, value); break; case "j": case "journal": _journal = ParseBoolean(name, value); break; case "maxidletime": case "maxidletimems": _maxIdleTime = ParseTimeSpan(name, value); break; case "maxlifetime": case "maxlifetimems": _maxLifeTime = ParseTimeSpan(name, value); break; case "maxpoolsize": _maxPoolSize = ParseInt32(name, value); break; case "maxstaleness": case "maxstalenessseconds": _maxStaleness = ParseTimeSpan(name, value); if (_maxStaleness.Value == TimeSpan.FromSeconds(-1)) { _maxStaleness = null; } break; case "minpoolsize": _minPoolSize = ParseInt32(name, value); break; case "readconcernlevel": _readConcernLevel = ParseEnum <ReadConcernLevel>(name, value); break; case "readpreference": _readPreference = ParseEnum <ReadPreferenceMode>(name, value); break; case "readpreferencetags": var tagSet = ParseReadPreferenceTagSets(name, value); if (_readPreferenceTags == null) { _readPreferenceTags = new List <TagSet> { tagSet }.AsReadOnly(); } else { _readPreferenceTags = _readPreferenceTags.Concat(new[] { tagSet }).ToList(); } break; case "replicaset": _replicaSet = value; break; case "safe": var safe = ParseBoolean(name, value); if (_w == null) { _w = safe ? 1 : 0; } else { if (safe) { // don't overwrite existing W value unless it's 0 var wCount = _w as WriteConcern.WCount; if (wCount != null && wCount.Value == 0) { _w = 1; } } else { _w = 0; } } break; case "localthreshold": case "localthresholdms": case "secondaryacceptablelatency": case "secondaryacceptablelatencyms": _localThreshold = ParseTimeSpan(name, value); break; case "slaveok": if (_readPreference != null) { throw new MongoConfigurationException("ReadPreference has already been configured."); } _readPreference = ParseBoolean(name, value) ? ReadPreferenceMode.SecondaryPreferred : ReadPreferenceMode.Primary; break; case "serverselectiontimeout": case "serverselectiontimeoutms": _serverSelectionTimeout = ParseTimeSpan(name, value); break; case "sockettimeout": case "sockettimeoutms": _socketTimeout = ParseTimeSpan(name, value); break; case "ssl": _ssl = ParseBoolean(name, value); break; case "sslverifycertificate": _sslVerifyCertificate = ParseBoolean(name, value); break; case "guids": case "uuidrepresentation": _uuidRepresentation = ParseEnum <GuidRepresentation>(name, value); break; case "w": _w = WriteConcern.WValue.Parse(value); break; case "wtimeout": case "wtimeoutms": _wTimeout = ParseTimeSpan(name, value); if (_wTimeout < TimeSpan.Zero) { throw new MongoConfigurationException($"{name} must be greater than or equal to 0."); } break; case "waitqueuemultiple": _waitQueueMultiple = ParseDouble(name, value); break; case "waitqueuesize": _waitQueueSize = ParseInt32(name, value); break; case "waitqueuetimeout": case "waitqueuetimeoutms": _waitQueueTimeout = ParseTimeSpan(name, value); break; default: _unknownOptions.Add(name, value); break; } }