FluentTextTable icon indicating copy to clipboard operation
FluentTextTable copied to clipboard

`System.InvalidOperationException` is thrown when string property is `string.Empty`

Open shuheydev opened this issue 5 years ago • 0 comments

Description

Output target object has string type property, and set string.Empty as its value, it occurs System.InvalidOperationException.

null is Ok, but "" and string.Empty occurs exception.

How to Reproduce

Define the class which has string type property,and set string.Empty as its value, then output table using WriteLinemethod.

    class Program
    {
        static void Main(string[] args)
        {
            var testList = new List<TestClass>
            {
                new TestClass
                {
                    Prop1="Test1",
                    Prop2=1,
                },
                new TestClass
                {
                    Prop1=string.Empty,
                    Prop2=2,
                }
            };

            Build.TextTable<TestClass>()
                 .WriteLine(testList);
        }
    }

    public class TestClass
    {
        public string Prop1 { get; set; }
        public int Prop2 { get; set; }
    }

Expected Behavior

I expect the table is output, and the property is output as blank cell.

 +-------+-------+
 | Prop1 | Prop2 |
 +-------+-------+
 | Test1 | 1     |
 +-------+-------+
 |       | 2     |
 +-------+-------+

Actual Behavior

System.InvalidOperationException: 'Sequence contains no elements'

Basic Information

  • FluentTextTable 1.0.0
  • .NET Core 3.1
  • Visual Studio 2019 16.6.5

shuheydev avatar Jul 31 '20 02:07 shuheydev