예제 #1
0
파일: D2oReader.cs 프로젝트: xvolks/Cookie
        private object ReadFieldVector(IDataReader reader, D2oFieldDefinition field, int vectorDimension)
        {
            int count = reader.ReadInt();

            Type vectorType = field.FieldType;

            for (int i = 0; i < vectorDimension; i++)
            {
                vectorType = vectorType.GetGenericArguments()[0];
            }

            lock (objectCreators) // We sometimes have error on objectCreators.Add(vectorType, creator) : mainlock allready in the dictionary
                if (!objectCreators.ContainsKey(vectorType))
                {
                    Func <object[], object> creator = CreateObjectBuilder(vectorType, new FieldInfo[0]);

                    objectCreators.Add(vectorType, creator);
                }

            var result = objectCreators[vectorType](new object[0]) as IList;

            for (int i = 0; i < count; i++)
            {
                vectorDimension++;
                try
                {
                    object obj = ReadField(reader, field, field.VectorTypes[vectorDimension - 1].Item1, vectorDimension);
                    result.Add(obj);
                }
                catch { }
                vectorDimension--;
            }

            return(result);
        }
예제 #2
0
파일: D2oReader.cs 프로젝트: xvolks/Cookie
        private object ReadField(IDataReader reader, D2oFieldDefinition field, D2oFieldType typeId,
                                 int vectorDimension = 0)
        {
            switch (typeId)
            {
            case D2oFieldType.Int:
                return(ReadFieldInt(reader));

            case D2oFieldType.Bool:
                return(ReadFieldBool(reader));

            case D2oFieldType.String:
                return(ReadFieldUTF(reader));

            case D2oFieldType.Double:
                return(ReadFieldDouble(reader));

            case D2oFieldType.I18N:
                return(ReadFieldI18n(reader));

            case D2oFieldType.UInt:
                return(ReadFieldUInt(reader));

            case D2oFieldType.List:
                return(ReadFieldVector(reader, field, vectorDimension));

            default:
                return(ReadFieldObject(reader));
            }
        }
예제 #3
0
        private void WriteFieldVector(BigEndianWriter writer, D2oFieldDefinition field, IList list, int vectorDimension)
        {
            writer.WriteInt(list.Count);

            for (int i = 0; i < list.Count; i++)
            {
                WriteField(writer, field, field.VectorTypes[vectorDimension], ++vectorDimension);
            }
        }
예제 #4
0
        private void WriteField(BigEndianWriter writer, D2oFieldDefinition field, dynamic obj, int vectorDimension = 0)
        {
            switch (field.TypeId)
            {
            case D2oFieldType.Int:
                WriteFieldInt(writer, (int)obj);
                break;

            case D2oFieldType.Bool:
                WriteFieldBool(writer, obj);
                break;

            case D2oFieldType.String:
                WriteFieldUTF(writer, obj);
                break;

            case D2oFieldType.Double:
                WriteFieldDouble(writer, obj);
                break;

            case D2oFieldType.I18N:
                WriteFieldI18n(writer, obj);
                break;

            case D2oFieldType.UInt:
                WriteFieldUInt(writer, (uint)obj);
                break;

            case D2oFieldType.List:
                WriteFieldVector(writer, field, obj, vectorDimension);
                break;

            default:
                WriteFieldObject(writer, obj);
                break;
            }
        }