void ReadSInstance(ProtoReader reader, SInstance sInstance, CLS_Environment environment) { List <CLS_Content.Value> values; List <string> keywords; GetSortMembers(sInstance, out values, out keywords); int fieldNumber = 0; while ((fieldNumber = reader.ReadFieldHeader()) > 0) { Type memberT = values[fieldNumber - 1].type; CLS_Content.Value memberV = values[fieldNumber - 1]; string sClassName = keywords[fieldNumber - 1]; if (memberT == null) { memberT = typeof(SInstance); sClassName = ((SType)memberV.type).Name; } Type itemType = GetItemType(memberT); if (itemType != null) { sClassName = sInstance.type.members[sClassName].type.keyword; // 数组判断 if (memberT.IsArray) { string itemClass = sClassName.Substring(0, sClassName.Length - 2); // 从 xxx[] 中提取xxx BasicList list = new BasicList(); do { list.Add(ReadField(reader, itemType, itemClass, environment)); } while (reader.TryReadFieldHeader(fieldNumber)); Array result = Array.CreateInstance(itemType, list.Count); list.CopyTo(result, 0); memberV.value = result; } // 列表判断 else { string itemClass = sClassName.Substring(5, sClassName.Length - 6); // 从 List<xxx> 中提取xxx ICLS_Type iType = environment.GetTypeByKeywordQuiet(sClassName); CLS_Content content = CLS_Content.NewContent(environment); memberV.value = iType.function.New(content, m_emptyParams).value; CLS_Content.PoolContent(content); IList list = (IList)memberV.value; do { list.Add(ReadField(reader, itemType, itemClass, environment)); } while (reader.TryReadFieldHeader(fieldNumber)); } } else { memberV.value = ReadField(reader, memberT, sClassName, environment); } } }
object ReadField(ProtoReader reader, Type memberT, string sClassName, CLS_Environment environment) { if (memberT == typeof(int)) { return(reader.ReadInt32()); } else if (memberT == typeof(uint)) { return(reader.ReadUInt32()); } else if (memberT == typeof(bool)) { return(reader.ReadBoolean()); } else if (memberT == typeof(byte)) { return(reader.ReadByte()); } else if (memberT == typeof(sbyte)) { return(reader.ReadSByte()); } else if (memberT == typeof(float)) { return(reader.ReadSingle()); } else if (memberT == typeof(double)) { return(reader.ReadDouble()); } else if (memberT == typeof(short)) { return(reader.ReadInt16()); } else if (memberT == typeof(ushort)) { return(reader.ReadUInt16()); } else if (memberT == typeof(long)) { return(reader.ReadInt64()); } else if (memberT == typeof(ulong)) { return(reader.ReadUInt64()); } else if (memberT == typeof(string)) { return(reader.ReadString()); } else if (memberT == typeof(byte[])) { return(ProtoReader.AppendBytes(null, reader)); } else if (memberT == typeof(SInstance)) { SubItemToken st = ProtoReader.StartSubItem(reader); CLS_Type_Class sClass = environment.GetTypeByKeywordQuiet(sClassName) as CLS_Type_Class; if (!sClass.compiled) { RuntimeCompilerClass(sClassName); } CLS_Content content = CLS_Content.NewContent(environment); CLS_Content.Value retVal = sClass.function.New(content, m_emptyParams); CLS_Content.PoolContent(content); SInstance sInstance = (SInstance)retVal.value; ReadSInstance(reader, sInstance, environment); ProtoReader.EndSubItem(st, reader); return(sInstance); } else { throw new NotImplementedException("未实现类型: " + memberT); } }