예제 #1
0
        private void ConvertCsObj(object csObj, IMPObject mpObj)
        {
            Type   type     = csObj.GetType();
            string fullName = type.FullName;

            if (!(mpObj is Serializable))
            {
                throw new Exception(string.Concat("Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableSFSType interface"));
            }
            IMPArray val = MPArray.NewInstance();

            mpObj.PutUtfString(CLASS_MARKER_KEY, fullName);
            mpObj.PutMPArray(CLASS_FIELDS_KEY, val);
            foreach (FieldInfo info in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                string        name    = info.Name;
                object        obj2    = info.GetValue(csObj);
                IMPObject     obj3    = MPObject.NewInstance();
                MPDataWrapper wrapper = WrapField(obj2);
                if (wrapper != null)
                {
                    obj3.PutUtfString(FIELD_NAME_KEY, name);
                    obj3.Put(FIELD_VALUE_KEY, wrapper);
                    val.AddMPObject(obj3);
                }
                else
                {
                    throw new Exception(string.Concat("Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", info.GetType().Name, " -- unsupported type!"));
                }
            }
        }
예제 #2
0
        private IMPArray DecodeMPArray(ByteArray buffer)
        {
            IMPArray   array = MPArray.NewInstance();
            MPDataType type  = (MPDataType)Convert.ToInt32(buffer.ReadByte());

            if (type != MPDataType.MP_ARRAY)
            {
                throw new Exception(string.Concat("Invalid MPDataType. Expected: ", MPDataType.MP_ARRAY, ", found: ", type));
            }
            int num = buffer.ReadShort();

            if (num < 0)
            {
                throw new Exception("Can't decode MPArray. Size is negative: " + num);
            }
            for (int i = 0; i < num; i++)
            {
                MPDataWrapper val = DecodeObject(buffer);
                if (val == null)
                {
                    throw new Exception("Could not decode SFSArray item at index: " + i);
                }
                array.Add(val);
            }
            return(array);
        }
예제 #3
0
        private IMPArray UnrollCollection(ICollection collection)
        {
            IMPArray array = MPArray.NewInstance();

            foreach (object item in collection)
            {
                array.Add(WrapField(item));
            }
            return(array);
        }
예제 #4
0
        private IMPArray UnrollArray(object[] arr)
        {
            IMPArray array = MPArray.NewInstance();

            foreach (object item in arr)
            {
                array.Add(WrapField(item));
            }
            return(array);
        }