/// <summary>Try and get the API object type by CLR type.</summary>
        /// <typeparam name="TObject">CLR type to lookup the API object type by.</typeparam>
        /// <param name="apiObjectType">The API object type if it exists in the API schema, null otherwise.</param>
        /// <returns>True if API object type exists in the API schema, false otherwise.</returns>
        public static bool TryGetApiObjectType <TObject>(this IApiSchema apiSchema, out IApiObjectType apiObjectType)
        {
            Contract.Requires(apiSchema != null);

            var clrType = typeof(TObject);

            return(apiSchema.TryGetApiObjectType(clrType, out apiObjectType));
        }
        /// <summary>Get the API object type by CLR type object.</summary>
        /// <param name="clrType">CLR type object to lookup the API object type by.</param>
        /// <returns>The API object type in the API schema, otherwise an exception is thrown.</returns>
        /// <exception cref="ApiSchemaException"></exception>
        public static IApiObjectType GetApiObjectType(this IApiSchema apiSchema, Type clrType)
        {
            Contract.Requires(apiSchema != null);
            Contract.Requires(clrType != null);

            if (apiSchema.TryGetApiObjectType(clrType, out var apiObjectType))
            {
                return(apiObjectType);
            }

            // Unable to get API object type by the given CLR type.
            var message = $"Unable to get API object type [clrType={clrType.Name}] in the API schema, API object type was not configured.";

            throw new ApiSchemaException(message);
        }
        /// <summary>Get the API object type by API type name.</summary>
        /// <param name="apiName">API type name to lookup the API object type by.</param>
        /// <returns>The API object type in the API schema, otherwise an exception is thrown.</returns>
        /// <exception cref="ApiSchemaException"></exception>
        public static IApiObjectType GetApiObjectType(this IApiSchema apiSchema, string apiName)
        {
            Contract.Requires(apiSchema != null);
            Contract.Requires(apiName.SafeHasContent());

            if (apiSchema.TryGetApiObjectType(apiName, out var apiObjectType))
            {
                return(apiObjectType);
            }

            // Unable to get API object type by the given API name.
            var message = $"Unable to get API object type [apiName={apiName}] in the API schema, API object type was not configured.";

            throw new ApiSchemaException(message);
        }
        /// <summary>Try and get the API resource type by CLR type object.</summary>
        /// <param name="clrResourceType">CLR resource type object to lookup the API resource type by.</param>
        /// <param name="apiResourceType">The API resource type if it exists in the API schema, null otherwise.</param>
        /// <returns>True if API resource type exists in the API schema, false otherwise.</returns>
        /// <remarks>If the CLR type exists but is an API complex object, then this method returns false.</remarks>
        public static bool TryGetApiResourceType(this IApiSchema apiSchema, Type clrResourceType, out IApiObjectType apiResourceType)
        {
            Contract.Requires(apiSchema != null);
            Contract.Requires(clrResourceType != null);

            apiResourceType = null;

            if (!apiSchema.TryGetApiObjectType(clrResourceType, out var apiObjectType))
            {
                return(false);
            }

            var apiObjectTypeKind = apiObjectType.GetApiObjectTypeKind();

            if (apiObjectTypeKind != ApiObjectTypeKind.ResourceType)
            {
                return(false);
            }

            apiResourceType = apiObjectType;
            return(true);
        }
        /// <summary>Try and get the API resource type by API type name.</summary>
        /// <param name="apiName">API type name to lookup the API resource type by.</param>
        /// <param name="apiResourceType">The API resource type if it exists in the API schema, null otherwise.</param>
        /// <returns>True if API resource type exists in the API schema, false otherwise.</returns>
        public static bool TryGetApiResourceType(this IApiSchema apiSchema, string apiName, out IApiObjectType apiResourceType)
        {
            Contract.Requires(apiSchema != null);
            Contract.Requires(apiName.SafeHasContent());

            apiResourceType = null;

            if (!apiSchema.TryGetApiObjectType(apiName, out var apiObjectType))
            {
                return(false);
            }

            var apiObjectTypeKind = apiObjectType.GetApiObjectTypeKind();

            if (apiObjectTypeKind != ApiObjectTypeKind.ResourceType)
            {
                return(false);
            }

            apiResourceType = apiObjectType;
            return(true);
        }