コード例 #1
0
        private void HandleApiObjectTypeAttribute(IApiSchemaBuilder apiSchemaBuilder,
                                                  ApiConventionSettings apiConventionSettings,
                                                  ApiPrecedenceStack apiPrecedenceStack,
                                                  Type clrType)
        {
            Contract.Requires(apiSchemaBuilder != null);
            Contract.Requires(apiConventionSettings != null);
            Contract.Requires(clrType != null);

            var apiObjectTypeAttribute = (ApiObjectTypeAttribute)Attribute.GetCustomAttribute(clrType, typeof(ApiObjectTypeAttribute));

            if (apiObjectTypeAttribute == null)
            {
                return;
            }

            if (ClrTypeDiscoveryRules.CanAddApiObjectType(clrType) == false)
            {
                return;
            }

            var apiDiscoverySettings = apiConventionSettings.ApiDiscoverySettings;
            var apiAnnotationDiscoveryPredicateResult = apiDiscoverySettings.ApiAnnotationDiscoveryPredicate?.Invoke(clrType) ?? true;

            if (apiAnnotationDiscoveryPredicateResult == false)
            {
                return;
            }

            if (apiObjectTypeAttribute.Excluded)
            {
                apiPrecedenceStack.Push(ApiPrecedenceLevel.Annotation);
                apiSchemaBuilder.Exclude(clrType);
                apiPrecedenceStack.Pop();
                return;
            }

            IApiObjectTypeBuilder ApiObjectTypeConfiguration(IApiObjectTypeBuilder apiObjectTypeBuilder)
            {
                apiPrecedenceStack.Push(ApiPrecedenceLevel.Annotation);
                if (String.IsNullOrWhiteSpace(apiObjectTypeAttribute.Name) == false)
                {
                    apiObjectTypeBuilder.HasName(apiObjectTypeAttribute.Name);
                }

                if (String.IsNullOrWhiteSpace(apiObjectTypeAttribute.Description) == false)
                {
                    apiObjectTypeBuilder.HasDescription(apiObjectTypeAttribute.Description);
                }

                apiPrecedenceStack.Pop();

                return(apiObjectTypeBuilder);
            }

            apiPrecedenceStack.Push(ApiPrecedenceLevel.Annotation);
            apiSchemaBuilder.ApiObjectType(clrType, ApiObjectTypeConfiguration);
            apiPrecedenceStack.Pop();
        }
コード例 #2
0
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Extension Methods
        /// <summary>Excludes the API type from the API schema.</summary>
        /// <typeparam name="T">CLR type that represents the API type to exclude.</typeparam>
        /// <returns>A fluent-style API schema builder for the API schema.</returns>
        public static IApiSchemaBuilder Exclude <T>(this IApiSchemaBuilder apiSchemaBuilder)
        {
            Contract.Requires(apiSchemaBuilder != null);

            var clrType = typeof(T);

            return(apiSchemaBuilder.Exclude(clrType));
        }