// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNetCore.Mvc.ApiExplorer
{
///
/// Extension methods for .
///
public static class ApiDescriptionExtensions
{
///
/// Gets the value of a property from the collection
/// using the provided value of as the key.
///
/// The type of the property.
/// The .
/// The property or the default value of .
public static T GetProperty(this ApiDescription apiDescription)
{
if (apiDescription == null)
{
throw new ArgumentNullException(nameof(apiDescription));
}
object value;
if (apiDescription.Properties.TryGetValue(typeof(T), out value))
{
return (T)value;
}
else
{
return default(T);
}
}
///
/// Sets the value of an property in the collection using
/// the provided value of as the key.
///
/// The type of the property.
/// The .
/// The value of the property.
public static void SetProperty(this ApiDescription apiDescription, T value)
{
if (apiDescription == null)
{
throw new ArgumentNullException(nameof(apiDescription));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
apiDescription.Properties[typeof(T)] = value;
}
}
}