private EnumTypeModelDescription GenerateEnumTypeModelDescription(Type modelType) { EnumTypeModelDescription enumDescription = new EnumTypeModelDescription { Name = ModelNameHelper.GetModelName(modelType), ModelType = modelType, Documentation = CreateDefaultDocumentation(modelType) }; bool hasDataContractAttribute = modelType.GetCustomAttribute<DataContractAttribute>() != null; foreach (FieldInfo field in modelType.GetFields(BindingFlags.Public | BindingFlags.Static)) { if (ShouldDisplayMember(field, hasDataContractAttribute)) { EnumValueDescription enumValue = new EnumValueDescription { Name = field.Name, Value = field.GetRawConstantValue().ToString() }; if (DocumentationProvider != null) { enumValue.Documentation = DocumentationProvider.GetDocumentation(field); } enumDescription.Values.Add(enumValue); } } GeneratedModels.Add(enumDescription.Name, enumDescription); return enumDescription; }
public EnumTypeModelDescription GenerateEnumTypeModelDescription(Type modelType) { EnumTypeModelDescription enumDescription = new EnumTypeModelDescription { Name = ModelNameHelper.GetModelName(modelType), ModelType = modelType, Documentation = CreateDefaultDocumentation(modelType) }; var attr = modelType.GetCustomAttributes(typeof(DescriptionAttribute), true).ToList(); enumDescription.Description = attr.Any() ? ((DescriptionAttribute)attr.First()).Description : string.Empty; attr = modelType.GetCustomAttributes(typeof(MetaDataAttribute), true).ToList(); enumDescription.Added = new DateTime(2014, 07, 01); if (attr.Any()) { var attrInfo = (MetaDataAttribute)attr.First(); enumDescription.Added = attrInfo.IsPublic ? attrInfo.AddedDate : (DateTime?)null; enumDescription.MarkType = attrInfo.MarkType; } bool hasDataContractAttribute = modelType.GetCustomAttribute<DataContractAttribute>() != null; var underlyingType = Enum.GetUnderlyingType(modelType); DateTime? addedDate = null; foreach (FieldInfo field in modelType.GetFields(BindingFlags.Public | BindingFlags.Static)) { if (ShouldDisplayMember(field, hasDataContractAttribute)) { attr = field.GetCustomAttributes(typeof(DescriptionAttribute), true).ToList(); var mTp = 0; var metaDataAttribute = modelType.GetCustomAttributes<MetaDataAttribute>().FirstOrDefault(); if (metaDataAttribute != null) mTp = metaDataAttribute.MarkType; var enumValue = new EnumValueDescription { Name = field.Name, Documentation = underlyingType.Name, Value = field.GetRawConstantValue().ToString(), Description = attr.Any() ? ((DescriptionAttribute)attr.First()).Description : string.Empty, AddedDate = enumDescription.Added, MarkType = enumDescription.MarkType > 0 ? enumDescription.MarkType : mTp }; attr = field.GetCustomAttributes(typeof(MetaDataAttribute), true).ToList(); enumValue.AddedDate = attr.Any() ? ((MetaDataAttribute)attr.First()).AddedDate : enumValue.AddedDate; enumValue.MarkType = attr.Any() ? ((MetaDataAttribute)attr.First()).MarkType : 0; if (!addedDate.HasValue || addedDate < enumValue.AddedDate) addedDate = enumValue.AddedDate; //if (DocumentationProvider != null) //{ // enumValue.Documentation = DocumentationProvider.GetDocumentation(field); //} enumDescription.Values.Add(enumValue); } } if (addedDate.HasValue && enumDescription.Added < addedDate.Value) enumDescription.Added = addedDate; if (GeneratedModels.Keys.FirstOrDefault(x => x == enumDescription.Name) == null) GeneratedModels.Add(enumDescription.Name, enumDescription); return enumDescription; }