Пример #1
0
        public override string GetSanitizedValue(object value, ReplaceForAttribute attribute)
        {
            if (value is null)
            {
                return(String.Empty);
            }

            string[] parts = (attribute.Pattern?.ToString() ?? "0,4,*")
                             .Split(",")
                             .ToArray();

            int  leftTrim  = parts.Length > 0 ? int.Parse(parts[0]) : 0;
            int  rightTrim = parts.Length > 1 ? int.Parse(parts[1]) : 4;
            char replace   = parts.Length > 2 ? parts[2][0] : '*';

            int    trimsCount    = leftTrim + rightTrim;
            string valueAsString = value.ToString() !;

            if (valueAsString.Length < trimsCount)
            {
                return(valueAsString);
            }

            return($"{valueAsString.Substring(0, leftTrim)}" +
                   $"{new String(replace, valueAsString.Length - trimsCount)}" +
                   $"{valueAsString.Substring(valueAsString.Length - rightTrim)}");
        }
Пример #2
0
        /// <summary>
        /// Attribute Pattern format: X,Y
        /// where X is number, e.g. 5 or 17 or 1999, represents the length of replacement string
        /// If Pattern is null or X is 0 then the length will be taken from the value length
        /// where Y is one character for replacement e.g. @ or # or A
        /// The defaults: 0,*
        /// </summary>
        public override string GetSanitizedValue(object value, ReplaceForAttribute attribute)
        {
            if (value is null)
            {
                return(String.Empty);
            }

            string valueAsString = value.ToString() !;

            string[] parts = (attribute.Pattern?.ToString() ?? "0,*")
                             .Split(",")
                             .ToArray();

            int  length  = parts.Length > 0 && parts[0][0] != '0' ? int.Parse(parts[0]) : valueAsString.Length;
            char replace = parts.Length > 1 ? parts[1][0] : '*';

            return(new String(replace, length));
        }
Пример #3
0
 public abstract string GetSanitizedValue(object value, ReplaceForAttribute attribute);