Exemplo n.º 1
0
 /// <summary>
 /// Initalizes a <see cref="FixedLengthFieldString"/> object with a definition of a set of fixed-length fields
 /// and a string. The string will be parsed and values stored in the string will be assigned to the fields.
 /// </summary>
 /// <param name="fields">Defintion of fields in the string.</param>
 /// <param name="s">The string to be parsed in to the fields.</param>
 public FixedLengthFieldString(FixedLengthFieldCollection fields, string s)
 {
     ParameterGuard.NullCheck(s, nameof(s));
     ParameterGuard.NullCheck(fields, nameof(fields));
     Fields = fields;
     Parse(s);
 }
Exemplo n.º 2
0
        public static void Log(ILogDefinition def, params object[] args)
        {
            ILogger logger = _logger;

            ParameterGuard.NullCheck(logger, nameof(_logger));
            logger.Log(def, args);
        }
Exemplo n.º 3
0
        public void ParameterGuard_NullCheck_CheckNullValueWithoutGivenMessage_ShouldThrowArgumentNullExceptionWithGivenParamNameAndMessage()
        {
            try
            {
                ParameterGuard.NullCheck <object>(null, ParameterName);
            }
            catch (ArgumentNullException ex)
            {
                ValidateExceptionParameterName(ex, ParameterName);

                // If value of ex.ParamName is expected, rethrow the ArgumentNullException to
                // make the test pass.
                throw;
            }
        }
Exemplo n.º 4
0
        public static string Pad(this string s, int length, PaddingCharPosition position, char paddingChar)
        {
            ParameterGuard.NullCheck(s, nameof(s));

            switch (position)
            {
            case PaddingCharPosition.Left:
                return(s.PadLeft(length, paddingChar));

            case PaddingCharPosition.Right:
                return(s.PadRight(length, paddingChar));

            default:
                throw new NotSupportedException($"The value of {nameof(position)} ({position}) is not supported.");
            }
        }
Exemplo n.º 5
0
        public static string TrimPaddingChar(this string s, PaddingCharPosition position, char paddingChar)
        {
            ParameterGuard.NullCheck(s, nameof(s));

            switch (position)
            {
            case PaddingCharPosition.Left:
                return(s?.TrimStart(paddingChar));

            case PaddingCharPosition.Right:
                return(s?.TrimEnd(paddingChar));

            default:
                throw new NotSupportedException($"The value of {nameof(position)} ({position}) is not supported.");
            }
        }
Exemplo n.º 6
0
        public void ParameterGuard_NullCheck_CheckNonNullValueWithoutGivenMessage_ShouldNotThrowException()
        {
            object nonNullObject = new object();

            ParameterGuard.NullCheck(nonNullObject, ParameterName);
        }