ClientConnection
Represents the connection options for a client.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.ClientModel.Primitives
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public readonly struct ClientConnection
{
public string Id { get; }
public string Locator { get; }
[System.Runtime.CompilerServices.Nullable(2)]
[field: System.Runtime.CompilerServices.Nullable(2)]
public object Credential {
[System.Runtime.CompilerServices.NullableContext(2)]
get;
}
public CredentialKind CredentialKind { get; }
public IReadOnlyDictionary<string, string> Metadata { get; }
public ClientConnection(string id, string locator, object credential, CredentialKind credentialKind)
{
this = new ClientConnection(id, locator, credential, credentialKind, null);
}
public ClientConnection(string id, string locator)
{
this = new ClientConnection(id, locator, null, CredentialKind.None, null);
}
internal ClientConnection(string id, string locator, CredentialKind credentialKind)
{
Credential = null;
Id = id;
Locator = locator;
CredentialKind = credentialKind;
Metadata = new Dictionary<string, string>();
}
public ClientConnection(string id, string locator, [System.Runtime.CompilerServices.Nullable(2)] object credential, CredentialKind credentialKind, [System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1,
1
})] IReadOnlyDictionary<string, string> metadata)
{
if (string.IsNullOrWhiteSpace(id))
throw new ArgumentException("Id cannot be null or empty.", "id");
if (string.IsNullOrWhiteSpace(locator))
throw new ArgumentException("Locator cannot be null or empty.", "locator");
if (credential == null && credentialKind != 0)
throw new ArgumentNullException("credential", "Credential cannot be null.");
if (metadata == null)
Metadata = new Dictionary<string, string>();
else
Metadata = metadata;
Id = id;
Locator = locator;
Credential = credential;
CredentialKind = credentialKind;
}
[System.Runtime.CompilerServices.NullableContext(2)]
public bool TryGetLocatorAsUri(out Uri uri)
{
return Uri.TryCreate(Locator, UriKind.Absolute, out uri);
}
public override string ToString()
{
return Id + " => " + Locator;
}
}
}