Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntTuple 형식 파싱 오류 제보 및 해결 방안 #33

Open
jinhosung96 opened this issue Aug 28, 2024 · 0 comments
Open

IntTuple 형식 파싱 오류 제보 및 해결 방안 #33

jinhosung96 opened this issue Aug 28, 2024 · 0 comments

Comments

@jinhosung96
Copy link

jinhosung96 commented Aug 28, 2024

namespace GoogleSheet.Type
{
    [Type(typeof((int, int)), new string[] { "(int,int)", "(Int32,Int32)" })]
    public class IntTupleX2Type : IType
    {
        public object DefaultValue => null;
        public object Read(string value)
        {
            var datas = ReadUtil.GetBracketValueToArray(value);
            if (datas.Length == 0 || datas.Length == 1 || datas.Length > 2)
            {
                throw new UGSValueParseException("Parse Faield => " + value + " To " + this.GetType().Name);
            }
            else
            {
                return (datas[0], datas[1]);
            }
        }

        public string Write(object value)
        {
            var tuple = (((int, int))value);
            return $"[{tuple.Item1},{tuple.Item2}]";
        }
    }
}

원본 코드에 따르면 시트에서 읽어들인 string 형식의 자료형을 int로 파싱하지 않고 적용하고 있다.

namespace GoogleSheet.Type
{
    [Type(typeof((int, int)), new string[] { "(int,int)", "(Int32,Int32)" })]
    public class IntTupleX2Type : IType
    {
        public object DefaultValue => null;

        public object Read(string value)
        {
            var datas = ReadUtil.GetBracketValueToArray(value);
            if (datas.Length == 0 || datas.Length == 1 || datas.Length > 2)
            {
                throw new UGSValueParseException("Parse Faield => " + value + " To " + this.GetType().Name);
            }

            (int, int) tuple;
            if (int.TryParse(datas[0], out tuple.Item1) && int.TryParse(datas[1], out tuple.Item2)) return tuple;
            throw new UGSValueParseException("Parse Faield => " + value + " To " + this.GetType().Name);
        }

        public string Write(object value)
        {
            var tuple = ((int, int))value;
            return $"[{tuple.Item1},{tuple.Item2}]";
        }
    }
}

다음과 같이 코드를 수정한다면 이슈를 해결할 수 있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant