Пример #1
0
        private static bool ShouldDisplayMember(MemberInfo member, bool hasDataContractAttribute)
        {
            JsonIgnoreAttribute          jsonIgnore         = member.GetCustomAttribute <JsonIgnoreAttribute>();
            XmlIgnoreAttribute           xmlIgnore          = member.GetCustomAttribute <XmlIgnoreAttribute>();
            IgnoreDataMemberAttribute    ignoreDataMember   = member.GetCustomAttribute <IgnoreDataMemberAttribute>();
            NonSerializedAttribute       nonSerialized      = member.GetCustomAttribute <NonSerializedAttribute>();
            ApiExplorerSettingsAttribute apiExplorerSetting = member.GetCustomAttribute <ApiExplorerSettingsAttribute>();

            bool hasMemberAttribute = member.DeclaringType.IsEnum ?
                                      member.GetCustomAttribute <EnumMemberAttribute>() != null :
                                      member.GetCustomAttribute <DataMemberAttribute>() != null;

            // Display member only if all the followings are true:
            // no JsonIgnoreAttribute
            // no XmlIgnoreAttribute
            // no IgnoreDataMemberAttribute
            // no NonSerializedAttribute
            // no ApiExplorerSettingsAttribute with IgnoreApi set to true
            // no DataContractAttribute without DataMemberAttribute or EnumMemberAttribute
            return(jsonIgnore == null &&
                   xmlIgnore == null &&
                   ignoreDataMember == null &&
                   nonSerialized == null &&
                   (apiExplorerSetting == null || !apiExplorerSetting.IgnoreApi) &&
                   (!hasDataContractAttribute || hasMemberAttribute));
        }
        private static bool ShouldDisplayMember(MemberInfo member, bool hasDataContractAttribute)
        {
            JsonIgnoreAttribute          jsonIgnore         = member.GetCustomAttribute <JsonIgnoreAttribute>();
            XmlIgnoreAttribute           xmlIgnore          = member.GetCustomAttribute <XmlIgnoreAttribute>();
            IgnoreDataMemberAttribute    ignoreDataMember   = member.GetCustomAttribute <IgnoreDataMemberAttribute>();
            NonSerializedAttribute       nonSerialized      = member.GetCustomAttribute <NonSerializedAttribute>();
            ApiExplorerSettingsAttribute apiExplorerSetting = member.GetCustomAttribute <ApiExplorerSettingsAttribute>();

            bool hasMemberAttribute = member.DeclaringType.IsEnum ?
                                      member.GetCustomAttribute <EnumMemberAttribute>() != null :
                                      member.GetCustomAttribute <DataMemberAttribute>() != null;

            return(jsonIgnore == null &&
                   xmlIgnore == null &&
                   ignoreDataMember == null &&
                   nonSerialized == null &&
                   (apiExplorerSetting == null || !apiExplorerSetting.IgnoreApi) &&
                   (!hasDataContractAttribute || hasMemberAttribute));
        }