//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
namespace Microsoft.SqlTools.DataProtocol.Contracts.Utilities
{
internal static class NullableUtils
{
///
/// Determines whether the type is .
///
/// The type.
///
/// true if is ; otherwise, false.
///
public static bool IsNullable(Type t)
{
return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>);
}
///
/// Unwraps the if necessary and returns the underlying value type.
///
/// The type.
/// The underlying value type the type was produced from,
/// or the type if the type is not .
///
public static Type GetUnderlyingTypeIfNullable(Type t)
{
return IsNullable(t) ? Nullable.GetUnderlyingType(t) : t;
}
}
}