private Func <ApiMutableSchema, ApiMutableEnumerationType> CreateApiMutableEnumerationTypeFactory(Type clrEnumerationType)
        {
            Contract.Requires(clrEnumerationType != null);

            ApiMutableEnumerationType ApiMutableEnumerationTypeFactory(ApiMutableSchema apiMutableSchema)
            {
                Contract.Requires(apiMutableSchema != null);

                // Apply conventions
                this.ApiPrecedenceStack.Push(ApiPrecedenceLevel.Convention);

                var apiConventionSet      = apiMutableSchema?.ApiConventionSet;
                var apiConventionSettings = apiMutableSchema?.ApiConventionSettings;

                this.ApplyApiEnumerationTypeNameConventions(clrEnumerationType, apiConventionSet, apiConventionSettings);
                this.ApplyApiEnumerationTypeConventions(apiConventionSet, apiConventionSettings);

                this.ApiPrecedenceStack.Pop();

                // Create API scalar type context
                var apiDefaultName            = clrEnumerationType.Name;
                var apiDefaultDescription     = clrEnumerationType.CreateDefaultApiEnumerationTypeDescription();
                var apiMutableEnumerationType = new ApiMutableEnumerationType
                {
                    ApiMutableSchema   = apiMutableSchema,
                    ApiName            = apiDefaultName,
                    ApiDescription     = apiDefaultDescription,
                    ClrEnumerationType = clrEnumerationType
                };

                return(apiMutableEnumerationType);
            }

            return(ApiMutableEnumerationTypeFactory);
        }
        private static IApiEnumerationType CreateApiEnumerationType(ApiMutableEnumerationType apiMutableEnumerationType)
        {
            Contract.Requires(apiMutableEnumerationType != null);

            var apiName              = apiMutableEnumerationType.ApiName;
            var apiDescription       = apiMutableEnumerationType.ApiDescription;
            var apiEnumerationValues = CreateApiEnumValues(apiMutableEnumerationType);
            var clrEnumerationType   = apiMutableEnumerationType.ClrEnumerationType;
            var apiEnumerationType   = ApiTypeFactory.CreateApiEnumerationType(apiName, apiDescription, apiEnumerationValues, clrEnumerationType);

            return(apiEnumerationType);
        }
        private static ApiEnumerationValueConfiguration GetOrAddApiEnumerationValueConfiguration(ApiMutableEnumerationType apiMutableEnumerationType,
                                                                                                 string clrName,
                                                                                                 int clrOrdinal,
                                                                                                 ApiPrecedenceLevel apiPrecedenceLevel,
                                                                                                 ApiPrecedenceStack apiPrecedenceStack)
        {
            Contract.Requires(apiMutableEnumerationType != null);
            Contract.Requires(clrName.SafeHasContent());
            Contract.Requires(apiPrecedenceStack != null);

            if (apiMutableEnumerationType.ApiEnumerationValueConfigurations.TryGetValue(clrOrdinal, out var apiEnumerationValueConfigurationExisting))
            {
                return(apiEnumerationValueConfigurationExisting);
            }

            var apiEnumerationValueConfigurationNew = new ApiEnumerationValueConfiguration(clrName, clrOrdinal, apiPrecedenceStack);

            apiMutableEnumerationType.ApiEnumerationValueConfigurations.Add(clrOrdinal, apiEnumerationValueConfigurationNew);

            ApiFrameworkLog.Trace($"Added {nameof(ApiEnumerationValue)} [{nameof(ApiEnumerationValue.ClrName)}={clrName}] at {apiPrecedenceLevel} Level".Indent(IndentConstants.ApiMutableEnumerationTypeModifier));

            return(apiEnumerationValueConfigurationNew);
        }
        private static IReadOnlyCollection <IApiEnumerationValue> CreateApiEnumValues(ApiMutableEnumerationType apiMutableEnumerationType)
        {
            Contract.Requires(apiMutableEnumerationType != null);

            var apiMutableSchema = apiMutableEnumerationType.ApiMutableSchema;
            var apiEnumerationValueConfigurations = apiMutableEnumerationType.ApiEnumerationValueConfigurations
                                                    .OrderBy(x => x.Key)
                                                    .Select(x => x.Value)
                                                    .ToList();
            var apiEnumValues = apiEnumerationValueConfigurations.Select(x => x.Create(apiMutableSchema))
                                .ToList();

            return(apiEnumValues);
        }