示例#1
0
        public static string Serialize(object obj)
        {
            var result = "";

            switch (Squirrel.TypeOf(obj))
            {
            case "null":
                result += "null";
                break;

            case "integer":
            case "float":
            case "bool":
                result += obj;
                break;

            case "string":
                result += "\"" + obj + "\"";
                break;

            case "table":
                result += "{";
                foreach (var(v1, v2) in (IEnumerable <(string, object)>)obj)
                {
                    result += v1 + ":" + Serialize(v2) + ",";
                }
                result += "}";
                break;

            case "array":
                result += "[";
                foreach (var v1 in (IEnumerable <object>)obj)
                {
                    result += Serialize(v1) + ",";
                }
                result += "]";
                break;

            case "function":
                result += "function()";
                break;

            case "instance":
                result += "instance";
                break;

            default:
                result += "unknown type: " + Squirrel.TypeOf(obj);
                break;
            }
            return(result);
        }