/// <summary> /// Provides the actual implementation for serializing a value of type <see cref="T" />. /// </summary> /// <param name="value">The value to serialize.</param> /// <param name="writer">The writer to serialize with.</param> protected override void SerializeImplementation(ref List <T> value, IDataWriter writer) { try { writer.BeginArrayNode(value.Count); for (int i = 0; i < value.Count; i++) { try { TSerializer.WriteValue(value[i], writer); } catch (Exception ex) { writer.Context.Config.DebugContext.LogException(ex); } } } finally { writer.EndArrayNode(); } }
/// <summary> /// Provides the actual implementation for serializing a value of type <see cref="T" />. /// </summary> /// <param name="value">The value to serialize.</param> /// <param name="writer">The writer to serialize with.</param> protected override void SerializeImplementation(ref KeyValuePair <TKey, TValue> value, IDataWriter writer) { KeySerializer.WriteValue(value.Key, writer); ValueSerializer.WriteValue(value.Value, writer); }
/// <summary> /// Writes from the specified value using the specified writer. /// </summary> /// <param name="value">The value to write from.</param> /// <param name="writer">The writer to use.</param> protected override void Write(ref AnimationCurve value, IDataWriter writer) { KeyframeSerializer.WriteValue(value.keys, writer); WrapModeSerializer.WriteValue(value.preWrapMode, writer); WrapModeSerializer.WriteValue(value.postWrapMode, writer); }
/// <summary> /// Writes from the specified value using the specified writer. /// </summary> /// <param name="value">The value to write from.</param> /// <param name="writer">The writer to use.</param> protected override void Write(ref Bounds value, IDataWriter writer) { Vector3Serializer.WriteValue(value.center, writer); Vector3Serializer.WriteValue(value.size, writer); }
/// <summary> /// Provides the actual implementation for serializing a value of type <see cref="!:T" />. /// </summary> /// <param name="value">The value to serialize.</param> /// <param name="writer">The writer to serialize with.</param> protected override void SerializeImplementation(ref T value, IDataWriter writer) { Delegate del = (Delegate)(object)value; Delegate[] invocationList = del.GetInvocationList(); if (invocationList.Length > 1) { // We're serializing an invocation list, not a single delegate // Serialize that array of delegates instead DelegateArraySerializer.WriteValue("invocationList", invocationList, writer); return; } // We're serializing just one delegate invocation MethodInfo methodInfo = del.Method; if (methodInfo.GetType().Name.Contains("DynamicMethod")) { writer.Context.Config.DebugContext.LogError("Cannot serialize delegate made from dynamically emitted method " + methodInfo + "."); return; } if (methodInfo.IsGenericMethodDefinition) { writer.Context.Config.DebugContext.LogError("Cannot serialize delegate made from the unresolved generic method definition " + methodInfo + "; how did this even happen? It should not even be possible to have a delegate for a generic method definition that hasn't been turned into a generic method yet."); return; } if (del.Target != null) { ObjectSerializer.WriteValue("target", del.Target, writer); } TypeSerializer.WriteValue("declaringType", methodInfo.DeclaringType, writer); StringSerializer.WriteValue("methodName", methodInfo.Name, writer); TypeSerializer.WriteValue("delegateType", del.GetType(), writer); ParameterInfo[] parameters; if (methodInfo.IsGenericMethod) { parameters = methodInfo.GetGenericMethodDefinition().GetParameters(); } else { parameters = methodInfo.GetParameters(); } Type[] signature = new Type[parameters.Length]; for (int i = 0; i < signature.Length; i++) { signature[i] = parameters[i].ParameterType; } TypeArraySerializer.WriteValue("signature", signature, writer); if (methodInfo.IsGenericMethod) { Type[] genericArguments = methodInfo.GetGenericArguments(); TypeArraySerializer.WriteValue("genericArguments", genericArguments, writer); } }