Exemple #1
0
        public override void Serialize(HessianOutput output, object map, string customTypeName)
        {
            var typeName = customTypeName ?? _type.FullName;
            var defIdx   = output.WriteMapDefinition(typeName, _fieldNames);

            if (defIdx < 0)
            {
                output.WriteMapStart(typeName);
                for (int i = 0; i < _fields.Length; i++)
                {
                    output.WriteString(_fieldNames[i]);
                    _fieldSerializers[i].WriteField(output, map);
                }
                output.WriteMapEnd();
            }
            else
            {
                output.WriteMapStart(defIdx);

                for (int i = 0; i < _fields.Length; i++)
                {
                    _fieldSerializers[i].WriteField(output, map);
                }
            }
        }
        public override void Serialize(HessianOutput output, object map, string customTypeName)
        {
            var typeName = customTypeName ?? _type.FullName;

            output.WriteMapStart(typeName);

            // entries
            foreach (var fieldInfo in _fields)
            {
                output.WriteString(fieldInfo.Name);
                output.WriteObject(fieldInfo.GetValue(map));
            }

            output.WriteMapEnd();
        }
        public override void Serialize(HessianOutput output, object map, string customTypeName)
        {
            var dict     = (IDictionary)map;
            var typeName = customTypeName;

            output.WriteMapStart(typeName);

            foreach (var key in dict.Keys)
            {
                output.WriteObject(key);
                output.WriteObject(dict[key]);
            }

            output.WriteMapEnd();
        }
Exemple #4
0
        public override void Serialize(HessianOutput output, object map, string customTypeName)
        {
            var typeName = customTypeName ?? _type.FullName;
            var value    = Enum.GetName(_type, map);

            var defIdx = output.WriteMapDefinition(typeName, _fieldNames);

            if (defIdx < 0)
            {
                output.WriteMapStart(typeName);
                output.WriteString("name");
                output.WriteString(value);
                output.WriteMapEnd();
            }
            else
            {
                output.WriteMapStart(defIdx);
                output.WriteString(value);
            }
        }
Exemple #5
0
 public abstract void Serialize(HessianOutput output, object map, string customTypeName);
Exemple #6
0
 public Serializer(HessianOutput output, TypeBindings typeBindings = null)
 {
     _output       = output ?? throw new ArgumentNullException(nameof(output));
     _typeBindings = typeBindings;
 }
 public override void WriteField(HessianOutput output, object obj)
 {
     _valueWriter(output, _getter(obj));
 }
Exemple #8
0
        public void Serialize(HessianOutput output, IEnumerable list, string customTypeName)
        {
            // not much use to serializer the concrete list type
            var typeName = customTypeName;

            var length = list is ICollection collection ? collection.Count : -1;

            var hasEnd = output.WriteListStart(length, typeName);

            switch (list)
            {
            //NOTE enum arrays get "falsly" matched by IList<int> and IEnumerable<int>
            case IList <int> intList when !IsEnumArray(list.GetType()):
                for (int i = 0; i < intList.Count; i++)
                {
                    output.WriteInt(intList[i]);
                }
                break;

            case IEnumerable <int> intEnum when !IsEnumArray(list.GetType()):
                foreach (var item in intEnum)
                {
                    output.WriteInt(item);
                }
                break;

            case IList <long> longList:
                for (int i = 0; i < longList.Count; i++)
                {
                    output.WriteLong(longList[i]);
                }
                break;

            case IEnumerable <long> longEnum:
                foreach (var item in longEnum)
                {
                    output.WriteLong(item);
                }
                break;

            case IList <double> doubleList:
                for (int i = 0; i < doubleList.Count; i++)
                {
                    output.WriteDouble(doubleList[i]);
                }
                break;

            case IEnumerable <double> doubleEnum:
                foreach (var item in doubleEnum)
                {
                    output.WriteDouble(item);
                }
                break;

            case IList <DateTime> dateList:
                for (int i = 0; i < dateList.Count; i++)
                {
                    output.WriteDate(dateList[i]);
                }
                break;

            case IEnumerable <DateTime> dateEnum:
                foreach (var item in dateEnum)
                {
                    output.WriteDate(item);
                }
                break;

            case IList <bool> boolList:
                for (int i = 0; i < boolList.Count; i++)
                {
                    output.WriteBool(boolList[i]);
                }
                break;

            case IEnumerable <bool> boolEnum:
                foreach (var item in boolEnum)
                {
                    output.WriteBool(item);
                }
                break;

            case IList objList:
                for (int i = 0; i < objList.Count; i++)
                {
                    output.WriteObject(objList[i]);
                }
                break;

            default:
                foreach (var item in list)
                {
                    output.WriteObject(item);
                }
                break;
            }

            if (hasEnd)
            {
                output.WriteListEnd();
            }
        }
 public abstract void WriteField(HessianOutput output, object obj);
Exemple #10
0
 public override void WriteField(HessianOutput output, object obj)
 {
     output.WriteObject(_getter(obj));
 }