Esempio n. 1
0
        public ExpandActionFilter(Expander expander, Dictionary <string, object> expandContext, Func <object, object, Exception, object> inspector, bool expandAll, JsonSerializerSettings jsonOptions = null, IServiceProvider serviceProvider = null) :
            base()
        {
            _expander           = expander;
            _context            = expandContext;
            _inspector          = inspector;
            _expandAllEndpoints = expandAll;
            _serviceProvider    = serviceProvider;

            JsonSerializerSettings settings = new JsonSerializerSettings();

            // if explicit settings are provided, use them
            if (jsonOptions != null)
            {
                settings = jsonOptions.DeepCopy();
            }

            // otherwise if we got a service provider, try to find it
            else if (serviceProvider != null)
            {
                settings = serviceProvider?
                           .GetService <IOptions <MvcJsonOptions> >()?
                           .Value?
                           .SerializerSettings ?? settings;
            }

            // Make sure these settings ignore nulls
            settings.NullValueHandling = NullValueHandling.Ignore;
            _jsonOptions = settings;
        }