Ejemplo n.º 1
0
    private void write(VO entity)
    {
        Type type = entity.GetType();

        FieldInfo[] fields = type.GetFields();
        foreach (FieldInfo fieldInfo in fields)
        {
            if (!fieldInfo.IsPublic)
            {
                continue;
            }
            bool   primitive = fieldInfo.FieldType.IsPrimitive;
            string varName   = fieldInfo.Name;
            string typeName  = fieldInfo.FieldType.Name;

            if (fieldInfo.FieldType.IsPrimitive)              //int float double long
            {
                writePrimitive(entity, varName, typeName);
                continue;
            }


            //非基本类型: string  object  array
            if (typeName == "String")            //字符串
            {
                writeString(entity.getVarValue <string> (varName), entity.getVarId(varName));
                continue;
            }
            //集合类
            if (typeName == "ArrayList")
            {
                writeArray(entity.getVarValue <ArrayList> (varName), entity.getVarId(varName));
            }

            if (typeName == "VO")
            {
                writeObject(entity.getVarValue <VO> (varName), entity.getVarId(varName), true);
            }
            else
            {
                //通过BaseType来找
                typeName = fieldInfo.FieldType.BaseType.Name;
                if (typeName == "VO")
                {
                    writeObject(entity.getVarValue <VO> (varName), entity.getVarId(varName), true);
                }
            }
            Console.WriteLine(varName + "  " + typeName + "  " + (primitive ? "true" :"false"));
        }
    }
Ejemplo n.º 2
0
    public DataEncoder(VO entity, byte identity = 0, bool writeClazzIdentifer = true)
    {
        this.entity = entity;

        if (identity == 0)
        {
            identity = (byte)DataType.Default;
        }
        else          //写入标识 ,当标识不等于DataType.Default时
        {
            memoryStream.WriteByte(identity);
        }
        this.identity = identity;

        if (writeClazzIdentifer)
        {
            if (!VoMapping.ContainsKey(entity.GetType().Name))
            {
                int i = 0;
            }
            int clazzIdentifer = VoMapping[entity.GetType().Name];
            writeByte2(clazzIdentifer);
        }
    }