예제 #1
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);
        }
예제 #2
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);
        }