예제 #1
0
            /// <summary>ToString 오버라이딩</summary>
            public override string ToString()
            {
                StringBuilder rtnValue = new StringBuilder();

                for (int cnti = 0; cnti < this.attribute_list.Count; cnti++)
                {
                    string str;
                    object value = Get(cnti);
                    switch (Type.GetTypeCode(value.GetType()))
                    {
                    case TypeCode.Decimal:
                    case TypeCode.Double:
                    case TypeCode.Int16:
                    case TypeCode.Int32:
                    case TypeCode.Int64:
                    case TypeCode.UInt16:
                    case TypeCode.UInt32:
                    case TypeCode.UInt64:
                    case TypeCode.Single:
                        str = string.Format(
                            "{0}\"{1}\":{2}", (cnti > 0 ? ", " : ""),
                            AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                            (Get(cnti) == null ? "" : AZString.Encode(AZString.ENCODE.JSON, value.ToString()))
                            );
                        break;

                    case TypeCode.DBNull:
                        str = string.Format(
                            "{0}\"{1}\":{2}", (cnti > 0 ? ", " : ""),
                            AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                            "null"
                            );
                        break;

                    case TypeCode.Boolean:
                        str = string.Format(
                            "{0}\"{1}\":{2}", (cnti > 0 ? ", " : ""),
                            AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                            ((bool)value) ? "true" : "false"
                            );
                        break;

                    default:
                        str = string.Format(
                            "{0}\"{1}\":\"{2}\"", (cnti > 0 ? ", " : ""),
                            AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                            (Get(cnti) == null ? "" : AZString.Encode(AZString.ENCODE.JSON, value.ToString()))
                            );
                        break;
                    }
                    rtnValue.Append(str);
                }
                return(rtnValue.ToString());
            }
예제 #2
0
        /// <summary>ToString에 대한 overriding, JSON형식의 {,} 문자 안쪽의 문자열을 생성</summary>
        override public string ToString()
        {
            StringBuilder builder = new StringBuilder();

            for (int cnti = 0; cnti < indexer.Count; cnti++)
            {
                try {
                    if (Get(cnti) == null)
                    {
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)) + "\"" + ":" + "null");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(AZData)))
                    {
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + GetKey(cnti) + "\"" + ":" + "{" + ((AZData)Get(cnti)).ToString() + "}");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(AZList)))
                    {
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + GetKey(cnti) + "\"" + ":" + "[" + ((AZList)Get(cnti)).ToString() + "]");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(string[])))
                    {
                        string[]      valueSrc = (string[])Get(cnti);
                        StringBuilder sBuilder = new StringBuilder();
                        for (int cntk = 0; cntk < valueSrc.Length; cntk++)
                        {
                            if (valueSrc[cntk] == null)
                            {
                                sBuilder.AppendFormat("{0}null", cntk > 0 ? "," : "");
                            }
                            else
                            {
                                sBuilder.AppendFormat("{0}\"{1}\"", cntk > 0 ? "," : "", AZString.Encode(AZString.ENCODE.JSON, valueSrc[cntk]));
                            }
                        }
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)) + "\"" + ":" + "[" + sBuilder.ToString() + "]");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(int[])))
                    {
                        string valueString = ((int[])Get(cnti)).Join(",");
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)) + "\"" + ":" + "[" + valueString + "]");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(long[])))
                    {
                        string valueString = ((long[])Get(cnti)).Join(",");
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)) + "\"" + ":" + "[" + valueString + "]");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(float[])))
                    {
                        string valueString = ((float[])Get(cnti)).Join(",");
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)) + "\"" + ":" + "[" + valueString + "]");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(double[])))
                    {
                        string valueString = ((double[])Get(cnti)).Join(",");
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)) + "\"" + ":" + "[" + valueString + "]");
                    }
                    else if (Get(cnti).GetType().Equals(typeof(bool[])))
                    {
                        string valueString = ((bool[])Get(cnti)).Join(",");
                        builder.Append((cnti > 0 ? ", " : "") + "\"" + AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)) + "\"" + ":" + "[" + valueString + "]");
                    }
                    else
                    {
                        string str;
                        object value = Get(cnti);
                        switch (Type.GetTypeCode(value.GetType()))
                        {
                        case TypeCode.Decimal: case TypeCode.Double:
                        case TypeCode.Int16:
                        case TypeCode.Int32:
                        case TypeCode.Int64:
                        case TypeCode.UInt16:
                        case TypeCode.UInt32:
                        case TypeCode.UInt64:
                        case TypeCode.Single:
                            str = string.Format(
                                "{0}\"{1}\":{2}", (cnti > 0 ? ", " : ""),
                                AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                                (Get(cnti) == null ? "" : AZString.Encode(AZString.ENCODE.JSON, value.ToString()))
                                );
                            break;

                        case TypeCode.DBNull:
                            str = string.Format(
                                "{0}\"{1}\":{2}", (cnti > 0 ? ", " : ""),
                                AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                                "null"
                                );
                            break;

                        case TypeCode.Boolean:
                            str = string.Format(
                                "{0}\"{1}\":{2}", (cnti > 0 ? ", " : ""),
                                AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                                ((bool)value) ? "true" : "false"
                                );
                            break;

                        case TypeCode.DateTime:
                            str = string.Format(
                                "{0}\"{1}\":\"{2}\"", (cnti > 0 ? ", " : ""),
                                AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                                ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss.fff")
                                );
                            break;

                        default:
                            str = string.Format(
                                "{0}\"{1}\":\"{2}\"", (cnti > 0 ? ", " : ""),
                                AZString.Encode(AZString.ENCODE.JSON, GetKey(cnti)),
                                (Get(cnti) == null ? "" : AZString.Encode(AZString.ENCODE.JSON, value.ToString()))
                                );
                            break;
                        }
                        builder.Append(str);
                    }
                }
                catch (Exception) {
                    builder.Append((cnti > 0 ? ", " : "") + "\"" + GetKey(cnti) + "\"" + ":\"\"");
                }
            }
            return(builder.ToString());
        }