/// <summary> /// Initiates a new instance of the <see cref="SpecializedAuthenticationCredentialsBase"/> class. /// </summary> /// <param name="authenticationCredential">The generic authentication credential.</param> /// <param name="supportedType">The method name this specialized class supports.</param> protected SpecializedAuthenticationCredentialsBase(AuthenticationCredentials authenticationCredential, string supportedType) { if (authenticationCredential == null) { throw new ArgumentNullException(nameof(authenticationCredential)); } if (authenticationCredential.Type != supportedType) { throw new InvalidOperationException(Resources.InvalidAuthenticationCredentialSupplied); } BaseAuthenticationCredential = authenticationCredential; SupportedType = supportedType; base.Type = SupportedType; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var authenticationCredentialObject = JObject.Load(reader); var authenticationCredential = new AuthenticationCredentials { Type = authenticationCredentialObject.Value <string>(TypePropertyName) }; var parameterProperties = authenticationCredentialObject.Properties() .Where(p => p.Name != TypePropertyName); foreach (var parameterProperty in parameterProperties) { authenticationCredential.Parameters.Add(parameterProperty.Name, parameterProperty.Value.ToString()); } return(authenticationCredential); }