private static LPCValue ParseIntType(string text) { int i; if (!int.TryParse(text, out i)) { //LogMgr.Error("无法将 " + text + " 转换为int"); i = 0; } return(LPCValue.Create(i)); }
// 转换成lpcvalue public LPCValue ConvertLpc() { LPCMapping lpcMap = LPCMapping.Empty; foreach (KeyValuePair <string, int> c in mOwner.columns) { lpcMap.Add(c.Key, properties[c.Value]); } return(LPCValue.Create(lpcMap)); }
private static LPCValue ParseAutoType(string text) { if (text.Length < 1) { return(LPCValue.Create(text)); } char first_char = text [0]; if (first_char == '@') { // alias string alias = text.Substring(1); if (!AliasMgr.ContainsAlias(alias)) { //LogMgr.Error("字段没有配置别名 " + alias); return(LPCValue.Create(text)); } object v = AliasMgr.Get(alias); if (v is string) { return(LPCValue.Create((string)v)); } if (v is int) { return(LPCValue.Create((int)v)); } throw new Exception(string.Format("Unexpected alias name: {0}", alias)); } if ((first_char == '"') || (first_char == ':')) { // string or buffer return(LPCRestoreString.RestoreFromString(text)); } if ((first_char == '(') && (text.Length > 1)) { char second_char = text [1]; if ((second_char == '{') || (second_char == '[')) { // mapping or array return(LPCRestoreString.RestoreFromString(text)); } } if (((first_char >= '0') && (first_char <= '9')) || (first_char == '.') || (first_char == '-')) { // number return(LPCRestoreString.RestoreFromString(text)); } return(LPCValue.Create(text)); }
private static LPCValue ParseStringType(string text) { return(LPCValue.Create(text)); }
/// <summary> /// 反序列化. /// </summary> public static CsvFile Deserialize(MemoryStream stream) { int ver = FileMgr.ReadInt(stream); if (ver != CsvFileMgr.Version) { NIDebug.Log("Csv版本 {0} 错误, 最新版本 {1}", ver, CsvFileMgr.Version); return(null); } // 文件名 string name = FileMgr.ReadString(stream); CsvFile csv = new CsvFile(name); csv.primaryKey = FileMgr.ReadString(stream); // 主key类型 var pkeyType = (LPC.LPCValue.ValueType)FileMgr.ReadInt(stream); // 列名 int n = FileMgr.ReadInt(stream); csv.columns = new Dictionary <string, int>(n); for (int i = 0; i < n; i++) { string k = FileMgr.ReadString(stream); int v = FileMgr.ReadInt(stream); csv.columns.Add(k, v); } // 行数 n = FileMgr.ReadInt(stream); csv.rows = new CsvRow[n]; // 主key的列 int pkeyIdx = csv.columns[csv.primaryKey]; // 每行主key for (var i = 0; i < n; i++) { var row = new CsvRow(csv); if (pkeyType == LPCValue.ValueType.INT) { int pkey = FileMgr.ReadInt(stream); row.Add(pkeyIdx, LPCValue.Create(pkey)); } else { string pkey = FileMgr.ReadString(stream); row.Add(pkeyIdx, LPCValue.Create(pkey)); } csv.AddRow(i, row); } // 行数据 for (int i = 0; i < n; i++) { int len = FileMgr.ReadInt(stream); csv.rows[i].rowData = new byte[len]; stream.Read(csv.rows[i].rowData, 0, len); } return(csv); }