예제 #1
0
        /// <summary>
        /// Sets a property in the validation transaction using the specified name and value.
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="transaction">The validation transaction.</param>
        /// <param name="name">The property name.</param>
        /// <param name="value">The property value.</param>
        /// <returns>The validation transaction, so that calls can be easily chained.</returns>
        public static OpenIddictValidationTransaction SetProperty <TProperty>(
            [NotNull] this OpenIddictValidationTransaction transaction,
            [NotNull] string name, [CanBeNull] TProperty value) where TProperty : class
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("The property name cannot be null or empty.", nameof(name));
            }

            if (value == null)
            {
                transaction.Properties.Remove(name);
            }

            else
            {
                transaction.Properties[name] = value;
            }

            return(transaction);
        }
        /// <summary>
        /// Sets a property in the validation transaction using the specified name and value.
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="transaction">The validation transaction.</param>
        /// <param name="name">The property name.</param>
        /// <param name="value">The property value.</param>
        /// <returns>The validation transaction, so that calls can be easily chained.</returns>
        public static OpenIddictValidationTransaction SetProperty <TProperty>(
            this OpenIddictValidationTransaction transaction,
            string name, TProperty?value) where TProperty : class
        {
            if (transaction is null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name));
            }

            if (value is null)
            {
                transaction.Properties.Remove(name);
            }

            else
            {
                transaction.Properties[name] = value;
            }

            return(transaction);
        }
        /// <summary>
        /// Retrieves a property value from the validation transaction using the specified name.
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="transaction">The validation transaction.</param>
        /// <param name="name">The property name.</param>
        /// <returns>The property value or <c>null</c> if it couldn't be found.</returns>
        public static TProperty?GetProperty <TProperty>(
            this OpenIddictValidationTransaction transaction, string name) where TProperty : class
        {
            if (transaction is null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(SR.GetResourceString(SR.ID0106), nameof(name));
            }

            if (transaction.Properties.TryGetValue(name, out var property) && property is TProperty result)
            {
                return(result);
            }

            return(null);
        }
예제 #4
0
        /// <summary>
        /// Retrieves a property value from the validation transaction using the specified name.
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="transaction">The validation transaction.</param>
        /// <param name="name">The property name.</param>
        /// <returns>The property value or <c>null</c> if it couldn't be found.</returns>
        public static TProperty GetProperty <TProperty>(
            [NotNull] this OpenIddictValidationTransaction transaction, [NotNull] string name) where TProperty : class
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("The property name cannot be null or empty.", nameof(name));
            }

            if (transaction.Properties.TryGetValue(name, out var property) && property is TProperty result)
            {
                return(result);
            }

            return(null);
        }
 /// <summary>
 /// Creates a new instance of the <see cref="BaseContext"/> class.
 /// </summary>
 protected BaseContext(OpenIddictValidationTransaction transaction)
 => Transaction = transaction ?? throw new ArgumentNullException(nameof(transaction));
 /// <summary>
 /// Creates a new instance of the <see cref="HandleIntrospectionResponseContext"/> class.
 /// </summary>
 public HandleIntrospectionResponseContext([NotNull] OpenIddictValidationTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ApplyIntrospectionRequestContext"/> class.
 /// </summary>
 public ApplyIntrospectionRequestContext([NotNull] OpenIddictValidationTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="PrepareCryptographyRequestContext"/> class.
 /// </summary>
 public PrepareCryptographyRequestContext([NotNull] OpenIddictValidationTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ExtractConfigurationResponseContext"/> class.
 /// </summary>
 public ExtractConfigurationResponseContext([NotNull] OpenIddictValidationTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="PrepareConfigurationRequestContext"/> class.
 /// </summary>
 public PrepareConfigurationRequestContext([NotNull] OpenIddictValidationTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="HandleCryptographyResponseContext"/> class.
 /// </summary>
 public HandleCryptographyResponseContext([NotNull] OpenIddictValidationTransaction transaction)
     : base(transaction)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="PrepareIntrospectionRequestContext"/> class.
 /// </summary>
 public PrepareIntrospectionRequestContext(OpenIddictValidationTransaction transaction)
     : base(transaction)
 {
 }