From 2b74850e5566764aebf78a1e0f3628341fa4da87 Mon Sep 17 00:00:00 2001 From: Newp Date: Sun, 4 Feb 2024 17:16:53 +0900 Subject: [PATCH] =?UTF-8?q?ArrayType=EC=97=90=EC=84=9C=20text=EA=B0=92?= =?UTF-8?q?=EC=9D=B4=20=EB=B9=88=EA=B0=92=EC=9D=B4=EB=9D=BC=EB=A9=B4=20?= =?UTF-8?q?=EB=B9=88=EB=B0=B0=EC=97=B4=EC=9D=84=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArrayConvertTests.cs | 42 ++++++++++++++----- .../Converters/ArrayCustomConverter.cs | 9 +++- .../Npgg.Configuration.csproj | 2 +- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/Npgg.Configuration.Tests/ArrayConvertTests.cs b/src/Npgg.Configuration.Tests/ArrayConvertTests.cs index 3874988..42950bc 100644 --- a/src/Npgg.Configuration.Tests/ArrayConvertTests.cs +++ b/src/Npgg.Configuration.Tests/ArrayConvertTests.cs @@ -16,22 +16,42 @@ public class ArrayConvertTests string csv = @"Key ,Values ,Tag 1,""1,2,3,4,5"",tag "; - [Fact] - public void StringListTest() - { + [Fact] + public void StringListTest() + { - var list = loader.Load>(csv); + var list = loader.Load>(csv); - Assert.Single(list); + Assert.Single(list); - var item = list.Last(); + var item = list.Last(); - Assert.Equal(1, item.Key); - Assert.Equal(5, item.Values.Length); - Assert.Equal("tag", item.Tag); - } + Assert.Equal(1, item.Key); + Assert.Equal(5, item.Values.Length); + Assert.Equal("tag", item.Tag); + } - [Fact] + + [Fact] + public void EmptyIntArrayTest() + { + + string csv = @"Key ,Values ,Tag +1,"""",tag "; + var list = loader.Load>(csv); + + Assert.Single(list); + + var item = list.Last(); + + Assert.Equal(1, item.Key); + Assert.Equal(0, item.Values.Length); + Assert.Equal("tag", item.Tag); + } + + + + [Fact] public void IntListTest() { diff --git a/src/Npgg.Configuration/Converters/ArrayCustomConverter.cs b/src/Npgg.Configuration/Converters/ArrayCustomConverter.cs index 13714b4..d640265 100644 --- a/src/Npgg.Configuration/Converters/ArrayCustomConverter.cs +++ b/src/Npgg.Configuration/Converters/ArrayCustomConverter.cs @@ -17,7 +17,14 @@ public ArrayCustomConverter(Type elementType) public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - var splited = value.ToString().Trim('\"').Split(','); + var text = value.ToString(); + + if(string.IsNullOrWhiteSpace(text)) + { + return Array.CreateInstance(this.itemType, 0); + } + + var splited = text.Trim('\"').Split(','); var array = Array.CreateInstance(this.itemType, splited.Length); diff --git a/src/Npgg.Configuration/Npgg.Configuration.csproj b/src/Npgg.Configuration/Npgg.Configuration.csproj index 65f5b6c..2516bf4 100644 --- a/src/Npgg.Configuration/Npgg.Configuration.csproj +++ b/src/Npgg.Configuration/Npgg.Configuration.csproj @@ -6,7 +6,7 @@ Csv,Tsv string to c# object deserializer https://github.com/Newp/Npgg.Configuration - 1.6.2 + 1.6.3 $(Version) https://github.com/Newp/Npgg.Configuration git