protected virtual void ModifyProperty(MemberInfo member, JsonProperty property)
        {
            if (property.PropertyType != typeof(DateTime) && property.PropertyType != typeof(DateTime?))
            {
                return;
            }

            if (ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault <DisableDateTimeNormalizationAttribute>(member) == null)
            {
                var converter = new AbpDateTimeConverter();

                // try to resolve MvcJsonOptions
                if (_useMvcDateTimeFormat)
                {
                    using (var mvcJsonOptions = _iocResolver.ResolveAsDisposable <IOptions <MvcJsonOptions> >())
                    {
                        _datetimeFormat = mvcJsonOptions.Object.Value.SerializerSettings.DateFormatString;
                    }
                }

                // apply DateTimeFormat only if not empty
                if (!_datetimeFormat.IsNullOrWhiteSpace())
                {
                    converter.DateTimeFormat = _datetimeFormat;
                }

                property.Converter = converter;
            }
        }
Example #2
0
        protected virtual void ModifyProperty(MemberInfo member, JsonProperty property)
        {
            if (property.PropertyType != typeof(DateTime) && property.PropertyType != typeof(DateTime?))
            {
                return;
            }

            if (ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault <DisableDateTimeNormalizationAttribute>(member) != null)
            {
                return;
            }

            var converter = new AbpDateTimeConverter();

            if (!_useMvcDateTimeFormat.HasValue)
            {
                lock (SyncObj)
                {
                    if (!_useMvcDateTimeFormat.HasValue)
                    {
                        using (var configuration = _iocResolver.ResolveAsDisposable <IAbpAspNetCoreConfiguration>())
                        {
                            _useMvcDateTimeFormat = configuration.Object.UseMvcDateTimeFormatForAppServices;

                            if (_useMvcDateTimeFormat.Value)
                            {
                                using (var mvcJsonOptions = _iocResolver.ResolveAsDisposable <IOptions <MvcNewtonsoftJsonOptions> >())
                                {
                                    _datetimeFormat = mvcJsonOptions.Object.Value.SerializerSettings.DateFormatString;
                                }
                            }
                        }
                    }
                }
            }

            // apply DateTimeFormat only if not empty
            if (!_datetimeFormat.IsNullOrWhiteSpace())
            {
                converter.DateTimeFormat = _datetimeFormat;
            }

            property.Converter = converter;
        }