uni-google-sheets icon indicating copy to clipboard operation
uni-google-sheets copied to clipboard

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

Open jinhosung96 opened this issue 1 year ago • 0 comments

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}]";
        }
    }
}

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

jinhosung96 avatar Aug 28 '24 05:08 jinhosung96