Example #1
0
        private static Func <object, ISerializeOptions, string> GetRedactedGetStringFunc(Type type, RedactAttribute redactAttribute)
        {
            if (type == typeof(string))
            {
                return((value, options) => redactAttribute.Redact((string)value, options.ShouldRedact));
            }

            if (type == typeof(bool) || type == typeof(bool?))
            {
                return((value, options) => redactAttribute.Redact((bool?)value, options.ShouldRedact));
            }

            if (type == typeof(DateTime) || type == typeof(DateTime?))
            {
                return((value, options) => redactAttribute.Redact((DateTime?)value, options.ShouldRedact));
            }

            if (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?))
            {
                return((value, options) => redactAttribute.Redact((DateTimeOffset?)value, options.ShouldRedact));
            }

            if (type == typeof(TimeSpan) || type == typeof(TimeSpan?))
            {
                return((value, options) => redactAttribute.Redact((TimeSpan?)value, options.ShouldRedact));
            }

            if (type == typeof(char) || type == typeof(char?))
            {
                return((value, options) => redactAttribute.Redact((char?)value, options.ShouldRedact, options.ShouldSerializeCharAsInt));
            }

            return((value, options) => redactAttribute.Redact(value, options.ShouldRedact));
        }
Example #2
0
        public string GetString(object value, ISerializeOptions options)
        {
            var type = value as Type;

            if (type == null)
            {
                return(null);
            }

            var typeString =
                _redactAttribute != null
                    ? _redactAttribute.Redact(type, options.ShouldRedact)
                    : GetStringValue(type);

            return(typeString);
        }
Example #3
0
        public string GetString(object value, ISerializeOptions options)
        {
            var uri = value as Uri;

            if (uri == null)
            {
                return(null);
            }

            var uriString =
                _redactAttribute != null
                    ? _redactAttribute.Redact(uri, options.ShouldRedact)
                    : uri.ToString();

            return(uriString);
        }
Example #4
0
        public string GetString(object value, ISerializeOptions options)
        {
            var enumValue = value as Enum;

            if (enumValue == null)
            {
                return(null);
            }

            var enumStringValue =
                _redactAttribute != null
                    ? _redactAttribute.Redact(enumValue, options.ShouldRedact)
                    : value.ToString();

            var combinedValue = value.GetType().Name + "." + enumStringValue;

            return(combinedValue);
        }
        private static Func<object, ISerializeOptions, string> GetRedactedGetStringFunc(Type type, RedactAttribute redactAttribute)
        {
            if (type == typeof(string))
            {
                return (value, options) => redactAttribute.Redact((string)value, options.ShouldRedact);
            }

            if (type == typeof(bool) || type == typeof(bool?))
            {
                return (value, options) => redactAttribute.Redact((bool?)value, options.ShouldRedact);
            }

            if (type == typeof(DateTime) || type == typeof(DateTime?))
            {
                return (value, options) => redactAttribute.Redact((DateTime?)value, options.ShouldRedact);
            }

            if (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?))
            {
                return (value, options) => redactAttribute.Redact((DateTimeOffset?)value, options.ShouldRedact);
            }

            if (type == typeof(TimeSpan) || type == typeof(TimeSpan?))
            {
                return (value, options) => redactAttribute.Redact((TimeSpan?)value, options.ShouldRedact);
            }

            return (value, options) => redactAttribute.Redact(value, options.ShouldRedact);
        }