์ค๋ฅ ๋ฉ์์ง๋ฅผ ๋ช ํํ ํ๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐ ํด์ผ ํ๋ pull ์์ฒญ์ ๋ณด์์ง๋ง ์ฌ์ ํ ์ถฉ๋ถํ ์ ์ฐ์ฑ์ ์ ๊ณตํ์ง ์์ต๋๋ค.
ํ์ฌ ์ฌ์ฉ์์๊ฒ ์ค๋ฅ์ ๋ํ ๋ ๋์ ์์ค์ ์ธ๋ถ ์ ๋ณด๋ฅผ ์ ๊ณตํ๊ธฐ ์ํด ๋ค์๊ณผ ๊ฐ์ด ์์ฑํด์ผ ํฉ๋๋ค.
``` C#
var e = ์ ๋ชฉ๋ก
csvReader.Configuration.ReadingExceptionCallback = (์, ํ) =>
{
foreach(ex.Data.Values์ var ์ค๋ฅ)
{
var ์ ๋ณด = error.ToString().Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
var ๊ฐ = ์ ๋ณด[4].Split(':')[1].Trim();
var ํ๋ = ์ ๋ณด[3].Split(':')[1].Trim();
e.Add(string.Format("ํ {1}, ํ๋ {2}์์ ๊ฐ {0}์(๋ฅผ) ์ฝ์ ์ ์์ต๋๋ค.",
๊ฐ, ํ.ํ, ํ๋));
}
};
// e๋ฅผ ์นํ์ด์ง๋ก ๋ฐํ(์: JSON)
This is relatively ok. It gives information where exactly parsing error has occured. However, as you can see, digging this information is ugly since I have to parse string to get the value and the field name. It would be nice if this information could be exposed via properties so that I could write something like this:
``` c#
csvReader.Configuration.ReadingExceptionCallback = (ex, row) =>
{
foreach (var error in row.Errors)
{
e.Add(string.Format("Could not read value {0} in row {1}, field {2}.",
error.Value, error.Row, error.FieldName));
}
};
๊ทธ๋ฌ๋ ์๋ ๊ด์ฐฎ์ต๋๋ค ... ์๋ํฉ๋๋ค. ๋ ์ค์ํ ๊ฒ์ ๋ค์ ์์ฒญ์
๋๋ค.
๋ํ ํ์ฑ์ด ์คํจํ ์ด์ ์ ๋ํ ์ ๋ณด๋ฅผ ์ ๊ณตํ ์ ์์ผ๋ฉด ์ข์ ๊ฒ์
๋๋ค.
ํ๋๊ฐ "๋นจ๊ฐ์" ๋๋ "ํ๋์" ๊ฐ๋ง ํ์ฉํ์ง๋ง ์ฌ์ฉ์๊ฐ "๋
ธ๋์"์ ์
๋ ฅํ๋ค๊ณ ๊ฐ์ ํด ๋ณด๊ฒ ์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ด ํด๊ฒฐํ ์ ์์ต๋๋ค.
c#
// in the MyClassMap : CsvClassMap<MyClass> class
Map(x => x.Color).ErrorMessage("Accepted values are 'Red' and 'Blue'");
...
// in the ReadingExceptionCallback
e.Add(string.Format("Could not read value {0} in row {1}, field {2}. {3}",
error.Value, error.Row, error.FieldName, error.Message));
์ด ๊ตฌ๋ฌธ์ ๊ฐ๋ฐ์์๊ฒ ๋ง์ ์ ์ฐ์ฑ์ ์ ๊ณตํ๊ณ ์ฌ์ฉ์์๊ฒ ๋ช ํํ ํผ๋๋ฐฑ์ ์ ๊ณตํฉ๋๋ค.
๋ค ์๊ฐ์ ๋งํด๋ด.
์ด๊ฒ์ ํฅ๋ฏธ๋ก์ด ์์ด๋์ด์ ๋๋ค. ์ง๊ธ์ ์ด๊ฒ์ ๊ธฐ๋ฅ์ผ๋ก ํ์ํ๊ณ ๋์ค์ ์์ธํ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
์ด ๊ธฐ๋ฅ ์์ฒญ์ ๋ ๋ฒ์งธ๋ก ํ๊ณ ์ถ์ต๋๋ค.
์ฌ๊ธฐ๊น์ง ์์ผ๋ ๊ฐ๋จํ ๊ฐ์ฌ์ ์ธ์ฌ๋ฅผ ์ ํ๊ณ ์ถ์ต๋๋ค. CsvHelper๋ ์ฌ๋ฌ ์์ค์์ ํ๋ฅญํฉ๋๋ค.
3.0์์๋ ๊ธฐ๋ณธ CsvHelperException
๊ฐ์ฒด์ ๋ชจ๋ ๊ฐ์ ๋ํ ์์ฑ์ด ์์ต๋๋ค. ์ฝ๋ฐฑ์ ๋ค์ ์ค ๊ฒ์ด๋ค CsvHelperException
๋์ Exception
. 3.0 ๋ฒ ํ๋ NuGet์ ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์ ํฅ๋ฏธ๋ก์ด ์์ด๋์ด์ ๋๋ค. ์ง๊ธ์ ์ด๊ฒ์ ๊ธฐ๋ฅ์ผ๋ก ํ์ํ๊ณ ๋์ค์ ์์ธํ ์ดํด๋ณด๊ฒ ์ต๋๋ค.