/// <summary> /// Reads the object as a custom type. /// </summary> private static object ReadAsCustomType(Type customType, SerializationInfo serInfo, StreamingContext ctx) { var ctorFunc = SerializableTypeDescriptor.Get(customType).SerializationCtor; var customObj = ctorFunc(serInfo, ctx); var wrapper = customObj as IObjectReference; return(wrapper == null ? customObj : wrapper.GetRealObject(ctx)); }
/// <summary> /// Register type. /// </summary> /// <param name="type">Type.</param> /// <param name="typeId">Type ID.</param> /// <param name="converter">Name converter.</param> /// <param name="idMapper">ID mapper.</param> /// <param name="forceTimestamp">Force timestamp serialization for DateTime fields..</param> /// <returns>Resulting serializer.</returns> internal BinaryReflectiveSerializerInternal Register(Type type, int typeId, IBinaryNameMapper converter, IBinaryIdMapper idMapper, bool forceTimestamp) { Debug.Assert(_wActions == null && _rActions == null); var fields = ReflectionUtils.GetAllFields(type).Where(x => !x.IsNotSerialized).ToList(); IDictionary <int, string> idMap = new Dictionary <int, string>(); foreach (FieldInfo field in fields) { string fieldName = BinaryUtils.CleanFieldName(field.Name); int fieldId = BinaryUtils.FieldId(typeId, fieldName, converter, idMapper); if (idMap.ContainsKey(fieldId)) { if (fieldName == idMap[fieldId]) { string baseClassName = field.DeclaringType != null ? field.DeclaringType.Name : null; throw new BinaryObjectException(string.Format( "{0} derives from {1} and hides field {2} from the base class. " + "Ignite can not serialize two fields with the same name.", type.Name, baseClassName, fieldName)); } throw new BinaryObjectException(string.Format( "Conflicting field IDs [type={0}, field1={1}, field2={2}, fieldId={3}])", type.Name, idMap[fieldId], fieldName, fieldId)); } idMap[fieldId] = fieldName; } fields.Sort(Compare); var wActions = new BinaryReflectiveWriteAction[fields.Count]; var rActions = new BinaryReflectiveReadAction[fields.Count]; for (int i = 0; i < fields.Count; i++) { BinaryReflectiveWriteAction writeAction; BinaryReflectiveReadAction readAction; BinaryReflectiveActions.GetTypeActions(fields[i], out writeAction, out readAction, _rawMode, forceTimestamp); wActions[i] = writeAction; rActions[i] = readAction; } var serDesc = SerializableTypeDescriptor.Get(type); return(new BinaryReflectiveSerializerInternal(wActions, rActions, _rawMode, serDesc)); }
/// <summary> /// Initializes a new instance of the <see cref="BinaryReflectiveSerializer"/> class. /// </summary> private BinaryReflectiveSerializerInternal(BinaryReflectiveWriteAction[] wActions, BinaryReflectiveReadAction[] rActions, bool raw, SerializableTypeDescriptor serializableDescriptor) { Debug.Assert(wActions != null); Debug.Assert(rActions != null); Debug.Assert(serializableDescriptor != null); _wActions = wActions; _rActions = rActions; _rawMode = raw; _serializableDescriptor = serializableDescriptor; }
/// <summary> /// Register type. /// </summary> /// <param name="type">Type.</param> /// <param name="typeId">Type ID.</param> /// <param name="converter">Name converter.</param> /// <param name="idMapper">ID mapper.</param> /// <param name="forceTimestamp">Force timestamp serialization for DateTime fields..</param> /// <returns>Resulting serializer.</returns> internal BinaryReflectiveSerializerInternal Register(Type type, int typeId, IBinaryNameMapper converter, IBinaryIdMapper idMapper, bool forceTimestamp) { Debug.Assert(_wActions == null && _rActions == null); var fields = ReflectionUtils.GetAllFields(type).Where(x => !x.IsNotSerialized).ToList(); IDictionary <int, string> idMap = new Dictionary <int, string>(); foreach (FieldInfo field in fields) { string fieldName = BinaryUtils.CleanFieldName(field.Name); int fieldId = BinaryUtils.FieldId(typeId, fieldName, converter, idMapper); if (idMap.ContainsKey(fieldId)) { throw new BinaryObjectException("Conflicting field IDs [type=" + type.Name + ", field1=" + idMap[fieldId] + ", field2=" + fieldName + ", fieldId=" + fieldId + ']'); } idMap[fieldId] = fieldName; } fields.Sort(Compare); var wActions = new BinaryReflectiveWriteAction[fields.Count]; var rActions = new BinaryReflectiveReadAction[fields.Count]; for (int i = 0; i < fields.Count; i++) { BinaryReflectiveWriteAction writeAction; BinaryReflectiveReadAction readAction; BinaryReflectiveActions.GetTypeActions(fields[i], out writeAction, out readAction, _rawMode, forceTimestamp); wActions[i] = writeAction; rActions[i] = readAction; } var serDesc = SerializableTypeDescriptor.Get(type); return(new BinaryReflectiveSerializerInternal(wActions, rActions, _rawMode, serDesc)); }
/// <summary> /// Initializes a new instance of the <see cref="SerializableSerializer"/> class. /// </summary> public SerializableSerializer(Type type) { IgniteArgumentCheck.NotNull(type, "type"); _serializableTypeDesc = SerializableTypeDescriptor.Get(type); }