public ModelDescription Generate(Type modelType, ModelDescriptionGenerator generator)
        {
            var enumDescription = new EnumTypeModelDescription
            {
                Name = ModelNameHelper.GetModelName(modelType),
                ModelType = modelType,
                Documentation = generator.CreateDefaultDocumentation(modelType)
            };
            var hasDataContractAttribute = modelType.GetCustomAttribute<DataContractAttribute>() != null;
            foreach (var field in modelType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                if (!ModelDescriptionGenerator.ShouldDisplayMember(field, hasDataContractAttribute)) continue;
                var enumValue = new EnumValueDescription
                {
                    Name = field.Name,
                    Value = field.GetRawConstantValue().ToString()
                };
                if (generator.DocumentationProvider != null)
                {
                    enumValue.Documentation = generator.DocumentationProvider.GetDocumentation(field);
                }
                enumDescription.Values.Add(enumValue);
            }
            generator.GeneratedModels.Add(enumDescription.Name, enumDescription);

            return enumDescription;
        }
Пример #2
0
        public ModelDescription Generate(Type modelType, ModelDescriptionGenerator generator)
        {
            var enumDescription = new EnumTypeModelDescription
            {
                Name          = ModelNameHelper.GetModelName(modelType),
                ModelType     = modelType,
                Documentation = generator.CreateDefaultDocumentation(modelType)
            };
            var hasDataContractAttribute = modelType.GetCustomAttribute <DataContractAttribute>() != null;

            foreach (var field in modelType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                if (!ModelDescriptionGenerator.ShouldDisplayMember(field, hasDataContractAttribute))
                {
                    continue;
                }
                var enumValue = new EnumValueDescription
                {
                    Name  = field.Name,
                    Value = field.GetRawConstantValue().ToString()
                };
                if (generator.DocumentationProvider != null)
                {
                    enumValue.Documentation = generator.DocumentationProvider.GetDocumentation(field);
                }
                enumDescription.Values.Add(enumValue);
            }
            generator.GeneratedModels.Add(enumDescription.Name, enumDescription);

            return(enumDescription);
        }
        public ModelDescription Generate(Type modelType, ModelDescriptionGenerator generator)
        {
            var simpleModelDescription = new SimpleTypeModelDescription
            {
                Name = ModelNameHelper.GetModelName(modelType),
                ModelType = modelType,
                Documentation = generator.CreateDefaultDocumentation(modelType)
            };
            generator.GeneratedModels.Add(simpleModelDescription.Name, simpleModelDescription);

            return simpleModelDescription;
        }
Пример #4
0
        public ModelDescription Generate(Type modelType, ModelDescriptionGenerator generator)
        {
            var simpleModelDescription = new SimpleTypeModelDescription
            {
                Name          = ModelNameHelper.GetModelName(modelType),
                ModelType     = modelType,
                Documentation = generator.CreateDefaultDocumentation(modelType)
            };

            generator.GeneratedModels.Add(simpleModelDescription.Name, simpleModelDescription);

            return(simpleModelDescription);
        }
 public void Test_Assert_ComplexProvider()
 {
     var generator = new ModelDescriptionGenerator(new HttpConfiguration());
     var provider = ModelProviderFactory.GetProvider(typeof (VipDemandDto));
     Assert.IsInstanceOf<ComplexModelProvider>(provider);
     var doc = generator.CreateDefaultDocumentation(typeof (VipDemandDto));
     Assert.AreEqual(doc, "VIP需求信息数据单元");
 }
        public ModelDescription Generate(Type modelType, ModelDescriptionGenerator generator)
        {
            var provider = new DocProvider();
            
            var complexModelDescription = new ComplexTypeModelDescription
            {
                Name = ModelNameHelper.GetModelName(modelType),
                ModelType = modelType,
                Documentation = generator.CreateDefaultDocumentation(modelType),
                ParameterDocumentation = provider.GetDocumentation(modelType)
            };

            generator.GeneratedModels.Add(complexModelDescription.Name, complexModelDescription);
            var hasDataContractAttribute = modelType.GetCustomAttribute<DataContractAttribute>() != null;
            var properties = modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (var property in properties)
            {
                if (!ModelDescriptionGenerator.ShouldDisplayMember(property, hasDataContractAttribute)) continue;
                var propertyModel = new ParameterDescription
                {
                    Name = GetMemberName(property, hasDataContractAttribute)
                };

                if (generator.DocumentationProvider != null)
                {
                    propertyModel.Documentation = generator.DocumentationProvider.GetDocumentation(property);
                }

                GenerateAnnotations(property, propertyModel);
                complexModelDescription.Properties.Add(propertyModel);
                propertyModel.TypeDescription = generator.GetOrCreateModelDescription(property.PropertyType);
            }

            var fields = modelType.GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (var field in fields)
            {
                if (!ModelDescriptionGenerator.ShouldDisplayMember(field, hasDataContractAttribute)) continue;
                var propertyModel = new ParameterDescription
                {
                    Name = GetMemberName(field, hasDataContractAttribute)
                };

                if (generator.DocumentationProvider != null)
                {
                    propertyModel.Documentation = generator.DocumentationProvider.GetDocumentation(field);
                }

                complexModelDescription.Properties.Add(propertyModel);
                propertyModel.TypeDescription = generator.GetOrCreateModelDescription(field.FieldType);
            }

            return complexModelDescription;
        }
Пример #7
0
        public ModelDescription Generate(Type modelType, ModelDescriptionGenerator generator)
        {
            var provider = new DocProvider();

            var complexModelDescription = new ComplexTypeModelDescription
            {
                Name                   = ModelNameHelper.GetModelName(modelType),
                ModelType              = modelType,
                Documentation          = generator.CreateDefaultDocumentation(modelType),
                ParameterDocumentation = provider.GetDocumentation(modelType)
            };

            generator.GeneratedModels.Add(complexModelDescription.Name, complexModelDescription);
            var hasDataContractAttribute = modelType.GetCustomAttribute <DataContractAttribute>() != null;
            var properties = modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in properties)
            {
                if (!ModelDescriptionGenerator.ShouldDisplayMember(property, hasDataContractAttribute))
                {
                    continue;
                }
                var propertyModel = new ParameterDescription
                {
                    Name = GetMemberName(property, hasDataContractAttribute)
                };

                if (generator.DocumentationProvider != null)
                {
                    propertyModel.Documentation = generator.DocumentationProvider.GetDocumentation(property);
                }

                GenerateAnnotations(property, propertyModel);
                complexModelDescription.Properties.Add(propertyModel);
                propertyModel.TypeDescription = generator.GetOrCreateModelDescription(property.PropertyType);
            }

            var fields = modelType.GetFields(BindingFlags.Public | BindingFlags.Instance);

            foreach (var field in fields)
            {
                if (!ModelDescriptionGenerator.ShouldDisplayMember(field, hasDataContractAttribute))
                {
                    continue;
                }
                var propertyModel = new ParameterDescription
                {
                    Name = GetMemberName(field, hasDataContractAttribute)
                };

                if (generator.DocumentationProvider != null)
                {
                    propertyModel.Documentation = generator.DocumentationProvider.GetDocumentation(field);
                }

                complexModelDescription.Properties.Add(propertyModel);
                propertyModel.TypeDescription = generator.GetOrCreateModelDescription(field.FieldType);
            }

            return(complexModelDescription);
        }