Example #1
0
        public bool TryGetApiEnumerationType(Type clrType, out IApiEnumerationType apiEnumerationType)
        {
            if (clrType != null)
            {
                return(this.ClrTypeToApiEnumerationTypeDictionary.TryGetValue(clrType, out apiEnumerationType));
            }

            apiEnumerationType = null;
            return(false);
        }
Example #2
0
        public bool TryGetApiEnumerationType(string apiName, out IApiEnumerationType apiEnumerationType)
        {
            if (!String.IsNullOrWhiteSpace(apiName))
            {
                return(this.ApiNameToApiEnumerationTypeDictionary.TryGetValue(apiName, out apiEnumerationType));
            }

            apiEnumerationType = null;
            return(false);
        }
        /// <summary>Gets the API enumeration value by CLR ordinal.</summary>
        /// <param name="clrOrdinal">CLR ordinal to lookup the API enumeration value by.</param>
        /// <returns>API enumeration value for the given CLR ordinal.</returns>
        /// <exception cref="ApiSchemaException">Is thrown if the API enumeration value is not found by CLR ordinal.</exception>
        // ReSharper disable once InvalidXmlDocComment
        public static IApiEnumerationValue GetApiEnumerationValueByClrOrdinal(this IApiEnumerationType apiEnumType, int clrOrdinal)
        {
            Contract.Requires(apiEnumType != null);

            if (apiEnumType.TryGetApiEnumerationValueByClrOrdinal(clrOrdinal, out var apiEnumValue))
            {
                return(apiEnumValue);
            }

            // Unable to get API enumeration value by the given CLR ordinal.
            var message = $"Unable to get API enumeration value [clrOrdinal={clrOrdinal}] in the API enumeration type [apiName={apiEnumType.ApiName} clrName={apiEnumType.ClrType.Name}].";

            throw new ApiSchemaException(message);
        }
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Extension Methods
        /// <summary>Gets the API enumeration value by API name.</summary>
        /// <param name="apiName">API name to lookup the API enumeration value by.</param>
        /// <returns>API enumeration value for the given API name.</returns>
        // ReSharper disable once InvalidXmlDocComment
        public static IApiEnumerationValue GetApiEnumerationValueByApiName(this IApiEnumerationType apiEnumType, string apiName)
        {
            Contract.Requires(apiEnumType != null);
            Contract.Requires(apiName != null);

            if (apiEnumType.TryGetApiEnumerationValueByApiName(apiName, out var apiEnumValue))
            {
                return(apiEnumValue);
            }

            // Unable to get API enumeration value by the given API name.
            var message = $"Unable to get API enumeration value [apiName={apiName}] in the API enumeration type [apiName={apiEnumType.ApiName} clrName={apiEnumType.ClrType.Name}].";

            throw new ApiSchemaException(message);
        }
        /// <summary>Try and get the API enumeration type by CLR type.</summary>
        /// <typeparam name="TEnumeration">CLR type to lookup the API enumeration type by.</typeparam>
        /// <param name="apiEnumerationType">The API enumeration type if it exists in the API schema, null otherwise.</param>
        /// <returns>True if API enumeration type exists in the API schema, false otherwise.</returns>
        public static bool TryGetApiEnumerationType <TEnumeration>(this IApiSchema apiSchema, out IApiEnumerationType apiEnumerationType)
        {
            Contract.Requires(apiSchema != null);

            var clrType = typeof(TEnumeration);

            return(apiSchema.TryGetApiEnumerationType(clrType, out apiEnumerationType));
        }
 public TryGetApiEnumerationTypeWithClrTypeUnitTest(string name, IApiSchema apiSchema, IApiEnumerationType expectedApiEnumerationType)
     : base(name)
 {
     this.ApiSchema = apiSchema;
     this.ExpectedApiEnumerationType = expectedApiEnumerationType;
 }