/// <summary> /// Constructor. /// </summary> /// <param name="options"><see cref="FixEnumsOptions"/>.</param> /// <param name="configureOptions">An <see cref="Action{FixEnumsOptions}"/> to configure options for filter.</param> public XEnumNamesParameterFilter(IOptions <FixEnumsOptions> options, Action <FixEnumsOptions> configureOptions = null) { if (options.Value != null) { configureOptions?.Invoke(options.Value); this._includeXEnumDescriptions = options.Value?.IncludeDescriptions ?? false; this._descriptionSources = options.Value?.DescriptionSource ?? DescriptionSources.DescriptionAttributes; this._applyFiler = options.Value?.ApplyParameterFilter ?? false; foreach (var filePath in options.Value?.IncludedXmlCommentsPaths) { if (File.Exists(filePath)) { this._xmlNavigators.Add(new XPathDocument(filePath).CreateNavigator()); } } } }
internal static List <OpenApiString> GetEnumValuesDescription(Type enumType, DescriptionSources descriptionSource, IEnumerable <XPathNavigator> xmlNavigators, bool includeRemarks = false) { var enumsDescriptions = new List <OpenApiString>(); foreach (var enumValue in Enum.GetValues(enumType)) { var enumDescription = string.Empty; try { switch (descriptionSource) { case DescriptionSources.DescriptionAttributes: enumDescription = GetDescriptionFromEnumOption(enumType, enumValue); break; case DescriptionSources.XmlComments: var memberInfo = enumType.GetMembers().FirstOrDefault(m => m.Name.Equals(enumValue.ToString(), StringComparison.InvariantCultureIgnoreCase)); enumDescription = TryGetMemberComments(memberInfo, xmlNavigators, includeRemarks); break; case DescriptionSources.DescriptionAttributesThenXmlComments: enumDescription = GetDescriptionFromEnumOption(enumType, enumValue); if (string.IsNullOrWhiteSpace(enumDescription)) { var memberInfo2 = enumType.GetMembers().FirstOrDefault(m => m.Name.Equals(enumValue.ToString(), StringComparison.InvariantCultureIgnoreCase)); enumDescription = TryGetMemberComments(memberInfo2, xmlNavigators, includeRemarks); } break; } } catch { } finally { if (!string.IsNullOrWhiteSpace(enumDescription)) { enumsDescriptions.Add(new OpenApiString(enumDescription)); } } } return(enumsDescriptions); }