Beispiel #1
0
        /// <summary>
        /// Pack object with assigned type
        /// </summary>
        public static GSFPacket Pack <T>(T obj)
        {
            Type          type   = typeof(T);
            PacketUtility packer = GetUtil(type);

            return(packer.pack(obj));
        }
Beispiel #2
0
        /// <summary>
        /// Pack object with unknown type
        /// </summary>
        public static GSFPacket Pack(object obj)
        {
            Type          type   = obj.GetType();
            PacketUtility packer = GetUtil(type);

            return(packer.pack(obj));
        }
        public override GSFPacket Pack(object obj)
        {
            Type          type = obj.GetType();
            PacketUtility util = GetUtil(type);

            return(util.pack(obj));
        }
        public override GSFPacket pack(object obj)
        {
            Type          type        = obj.GetType();
            Type          elementType = type.GetElementType();
            TypeInfo      typeInfo    = PackType(type);
            PacketUtility util        = GetUtil(elementType);
            int           length      = (int)type.GetProperty("Length").GetValue(obj);
            MethodInfo    getMethod   = type.GetMethod("Get");

            GSFPacket[] values = new GSFPacket[length];
            for (int i = 0; i < length; i++)
            {
                values[i] = util.pack(getMethod.Invoke(obj, new object[] { i }));
            }
            return(new GSFPacket(classID, new object[] { typeInfo, values }));
        }
        public override GSFPacket pack(object dict)
        {
            Type dictType = dict.GetType();

            Type[]        genericArgs = dictType.GetGenericArguments();
            TypeInfo      typeArgs    = PackType(dictType);
            int           length      = (int)dictType.GetProperty("Count").GetValue(dict);
            Type          pairType    = typeof(KeyValuePair <,>).MakeGenericType(genericArgs);
            PropertyInfo  keyProp     = pairType.GetProperty("Key");
            PacketUtility keyUtil     = GetUtil(keyProp.PropertyType);
            PropertyInfo  valProp     = pairType.GetProperty("Value");
            PacketUtility valUtil     = GetUtil(valProp.PropertyType);
            IEnumerable   e           = (IEnumerable)dict;

            object[] values = new object[length * 2];
            int      p      = 0;

            foreach (var pair in e)
            {
                values[p++] = keyUtil.pack(keyProp.GetValue(pair));
                values[p++] = valUtil.pack(valProp.GetValue(pair));
            }
            return(new GSFPacket(100, new object[] { typeArgs, values }));
        }
 public override GSFPacket pack(object obj)
 {
     return(proxy.pack(obj));
 }