protected override void OnMobileDeserializeState(ISerializationContext context) { this.Value = context.GetState<object>("v"); this.TypeName = context.GetState<string>("t"); base.OnMobileDeserializeState(context); }
internal ServerInfo(ISerializationContext context, IValueReader reader) { if (reader == null) throw new ArgumentNullException ("reader"); Deserialize (context, reader); }
protected override void OnMobileSerializeState(ISerializationContext context) { base.OnMobileSerializeState(context); context.AddState("v", this.Value); context.AddState("t", this.TypeName); }
/// <summary> /// Serializes the member. /// </summary> /// <param name="context">The context.</param> /// <param name="memberValue">The member value.</param> public override void SerializeMember(ISerializationContext context, MemberValue memberValue) { base.SerializeMember(context, memberValue); var value = memberValue.Value; if (value != null) { var valueType = value.GetType(); if (valueType.IsGenericTypeEx()) { if (valueType.GetGenericTypeDefinitionEx() == typeof(KeyValuePair<,>)) { var keyProperty = valueType.GetPropertyEx("Key"); var valueProperty = valueType.GetPropertyEx("Value"); var kvpKey = keyProperty.GetValue(value, null); var kvpValue = valueProperty.GetValue(value, null); var finalValue = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}", Prefix, Splitter, keyProperty.PropertyType, valueProperty.PropertyType, ObjectToStringHelper.ToString(kvpKey), ObjectToStringHelper.ToString(kvpValue)); memberValue.Value = finalValue; } } } }
/// <summary> /// Deserializes the member. /// </summary> /// <param name="context">The context.</param> /// <param name="memberValue">The member value.</param> public override void DeserializeMember(ISerializationContext context, MemberValue memberValue) { var valueAsString = memberValue.Value as string; if (!string.IsNullOrEmpty(valueAsString)) { if (valueAsString.StartsWith(Prefix)) { var splittedValues = valueAsString.Split(new[] { Splitter }, StringSplitOptions.None); var keyValuePairType = typeof(KeyValuePair<,>); var keyType = TypeCache.GetTypeWithoutAssembly(splittedValues[1]); var valueType = TypeCache.GetTypeWithoutAssembly(splittedValues[2]); var keyValue = splittedValues[3]; var valueValue = splittedValues[4]; // TODO: consider caching var keyValuePairGenericType = keyValuePairType.MakeGenericType(keyType, valueType); var key = StringToObjectHelper.ToRightType(keyType, keyValue); var value = StringToObjectHelper.ToRightType(valueType, valueValue); var keyValuePair = Activator.CreateInstance(keyValuePairGenericType, new [] { key, value }); memberValue.Value = keyValuePair; } } base.DeserializeMember(context, memberValue); }
public ChannelChangeInfo(ISerializationContext context, IValueReader reader) { if (reader == null) throw new ArgumentNullException("reader"); Deserialize (context, reader); }
private NetworkEntity ReadEntity(ISerializationContext context, IValueReader reader) { var entity = new NetworkEntity (reader.ReadString (), EntityType.Client); entity.NetworkID = reader.ReadUInt16 (); UInt16 fieldCount = reader.ReadUInt16 (); for (int f = 0; f < fieldCount; f++) { string name = reader.ReadString (); ushort typeID = reader.ReadUInt16 (); Type type; context.TypeMap.TryGetType (typeID, out type); object value; if (type == typeof (Vector2)) value = reader.Read (context, Vector2Serializer.Instance); else if (type == typeof (Vector3)) value = reader.Read (context, Vector3Serializer.Instance); else value = reader.Read (context, type); entity.Fields.Add (name, new PropertyGroup (value, type)); } return entity; }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { int[] sourceIds = new int[reader.ReadInt32()]; for (int i = 0; i < sourceIds.Length; ++i) sourceIds[i] = reader.ReadInt32(); this.SourceIds = sourceIds; }
public override void WritePayload (ISerializationContext context, IValueWriter writer) { if (writer.WriteBool (SenderId != null)) writer.WriteString (SenderId); writer.WriteInt32 (GroupId); writer.WriteString (Text); }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { AudioSource[] sourceInfos = new AudioSource[reader.ReadInt32()]; for (int i = 0; i < sourceInfos.Length; ++i) sourceInfos[i] = new AudioSource (context, reader); this.Sources = sourceInfos; }
public static TextReader Normalize(TextReader tr, ISerializationContext ctx) { string s = tr.ReadToEnd(); TextReader reader = Normalize(s, ctx); tr.Close(); return reader; }
public override void SetObjectData(ISerializationData dataHolder, ISerializationContext context) { base.SetObjectData(dataHolder, context); if (dataHolder.ContainsField("Priority")) Priority = dataHolder.GetValue<float>("Priority"); else Priority = context.Context as float? ?? DEFAULT_ACTION_PRIORITY; }
public override void ReadPayload (ISerializationContext context, IValueReader reader) { if (reader.ReadBool()) SenderId = reader.ReadString(); GroupId = reader.ReadInt32(); Text = reader.ReadString(); }
public override void WritePayload(ISerializationContext context, IValueWriter writer) { using (var ms = new MemoryStream()) { ScreenFrame.Save(ms, ImageFormat.Png); writer.WriteBytes(ms.GetBuffer()); } }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { int numUsers = reader.ReadInt32(); IUser[] users = new IUser[numUsers]; for (int i = 0; i < users.Length; ++i) users[i] = new User (reader.ReadInt32(), reader.ReadString()); Users = users; }
public virtual void RegisterId(string id, object value, ISerializationContext context) { if (value != null) { var type = Serializer.GetSerializationInfo(value.GetType(), true); InsertIntoIdStore(id, value, type); context.Register(value, new Uri(id, UriKind.Relative), this); } }
public override void WritePayload(ISerializationContext context, IValueWriter writer) { writer.WriteInt32 (Entities.Count); foreach (SnapshotEntity sentity in Entities) { WriteEntity (sentity.Entity, context, writer); } }
public override void DeserializeMember(ISerializationContext context, MemberValue memberValue) { if (string.Equals(memberValue.Name, "ProjectTypes")) { // TODO: Match the list with WP8 => WP80 somehow? } base.DeserializeMember(context, memberValue); }
public ItemValueSerializerNode(object value, TypeSpec expectedBaseType, string expandPath, ISerializationContext context, ISerializerNode parentNode, bool isRemoved = false) : base(expectedBaseType, expandPath, context, parentNode, isRemoved) { Value = value; }
public PropertyValueSerializerNode( ISerializerNode parentNode, PropertySpec property) { if (parentNode == null) throw new ArgumentNullException("parentNode"); if (property == null) throw new ArgumentNullException("propertyMapping"); this.parentNode = parentNode; this.property = property; context = parentNode.Context; }
/// <summary> /// Normalizes line endings, converting "\r" into "\r\n" and "\n" into "\r\n". /// </summary> public static TextReader Normalize(string s, ISerializationContext ctx) { // Replace \r and \n with \r\n. s = Regex.Replace(s, @"((\r(?=[^\n]))|((?<=[^\r])\n))", "\r\n"); ISerializationSettings settings = ctx.GetService(typeof(ISerializationSettings)) as ISerializationSettings; if (settings == null || !settings.EnsureAccurateLineNumbers) s = RemoveEmptyLines(UnwrapLines(s)); return new StringReader(s); }
public virtual void GetObjectData(ISerializationData dataHolder, ISerializationContext context) { dataHolder.SetValue("Id", Id); dataHolder.SetValue("Type", Type); dataHolder.SetValue("Subject", Subject); dataHolder.SetValue("Timestamp", Timestamp); if (m_linkedEmotions.Count > 0) { dataHolder.SetValue("LinkedEmotions", m_linkedEmotions.ToArray()); } }
/// <summary> /// Serializes the provided object asynchronously. /// </summary> /// <param name="obj">The object.</param> /// <param name="textWriter">The <see cref="TextWriter"/> used to write the object content.</param> /// <param name="context">The context.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// A Task promising the serialized object as a string. /// </returns> public Task SerializeAsync( object obj, TextWriter textWriter, ISerializationContext context = null, CancellationToken cancellationToken = default(CancellationToken)) { Contract.Requires(textWriter != null); Contract.Ensures(Contract.Result<Task>() != null); return Contract.Result<Task>(); }
public ItemValueSerializerNode( object value, TypeSpec expectedBaseType, string expandPath, ISerializationContext context, ISerializerNode parentNode, bool isRemoved = false) { this.value = value; this.expectedBaseType = expectedBaseType; this.expandPath = expandPath; this.context = context; this.parentNode = parentNode; this.isRemoved = isRemoved; }
protected SerializerNode(TypeSpec expectedBaseType, string expandPath, ISerializationContext context, ISerializerNode parentNode, bool isRemoved = false) { ExpectedBaseType = expectedBaseType; ExpandPath = expandPath; Context = context; ParentNode = parentNode; IsRemoved = isRemoved; }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { int entityCount = reader.ReadInt32 (); Entities = new List<SnapshotEntity>(entityCount); // Read in the entities for (int i = 0; i < entityCount; i++) { NetworkEntity entity = ReadEntity(context, reader); Entities.Add (new SnapshotEntity (entity, true)); } }
/// <summary> /// Gets a serializer for the provided context. /// </summary> /// <param name="context">The context.</param> /// <returns> /// The serializer. /// </returns> public ISerializer GetSerializer(ISerializationContext context = null) { context = context ?? new SerializationContext(typeof(JsonFormat)); var formatType = context.FormatType ?? typeof(JsonFormat); var serializer = this.serializerFactories.TryGetValue(formatType); if (serializer == null) { throw new KeyNotFoundException(string.Format(Strings.DefaultSerializationService_SerializerNotFound_Exception, formatType)); } return serializer.CreateExport().Value; }
/// <summary> /// Serializes a tag structure into a context. /// </summary> /// <param name="context">The serialization context to use.</param> /// <param name="tagStructure">The tag structure.</param> public void Serialize(ISerializationContext context, object tagStructure, uint? offset = null) { // Serialize the structure to a data block var info = new TagStructureInfo(tagStructure.GetType(), _version); context.BeginSerialize(info); var tagStream = new MemoryStream(); var structBlock = context.CreateBlock(); SerializeStruct(context, tagStream, structBlock, info, tagStructure); // Finalize the block and write all of the tag data out var mainStructOffset = offset.HasValue ? offset.Value : structBlock.Finalize(tagStream); var data = tagStream.ToArray(); context.EndSerialize(info, data, mainStructOffset); }
/// <summary> /// Returns a serializer that can be used to serialize and object /// of type <paramref name="objectType"/>. /// <note> /// TODO: Add support for caching. /// </note> /// </summary> /// <param name="objectType">The type of object to be serialized.</param> /// <param name="ctx">The serialization context.</param> virtual public ISerializer Build(Type objectType, ISerializationContext ctx) { if (objectType != null) { ISerializer s = null; if (typeof(IAttachment).IsAssignableFrom(objectType)) s = new AttachmentSerializer(); else if (typeof(IAttendee).IsAssignableFrom(objectType)) s = new AttendeeSerializer(); else if (typeof(IDateTime).IsAssignableFrom(objectType)) s = new DateTimeSerializer(); else if (typeof(IFreeBusyEntry).IsAssignableFrom(objectType)) s = new FreeBusyEntrySerializer(); else if (typeof(IGeographicLocation).IsAssignableFrom(objectType)) s = new GeographicLocationSerializer(); else if (typeof(IOrganizer).IsAssignableFrom(objectType)) s = new OrganizerSerializer(); else if (typeof(IPeriod).IsAssignableFrom(objectType)) s = new PeriodSerializer(); else if (typeof(IPeriodList).IsAssignableFrom(objectType)) s = new PeriodListSerializer(); else if (typeof(IRecurrencePattern).IsAssignableFrom(objectType)) s = new RecurrencePatternSerializer(); else if (typeof(IRequestStatus).IsAssignableFrom(objectType)) s = new RequestStatusSerializer(); else if (typeof(IStatusCode).IsAssignableFrom(objectType)) s = new StatusCodeSerializer(); else if (typeof(ITrigger).IsAssignableFrom(objectType)) s = new TriggerSerializer(); else if (typeof(IUTCOffset).IsAssignableFrom(objectType)) s = new UTCOffsetSerializer(); else if (typeof(IWeekDay).IsAssignableFrom(objectType)) s = new WeekDaySerializer(); // Default to a string serializer, which simply calls // ToString() on the value to serialize it. else s = new StringSerializer(); // Set the serialization context if (s != null) s.SerializationContext = ctx; return s; } return null; }
/// <summary> /// Returns a serializer that can be used to serialize and object /// of type <paramref name="objectType"/>. /// <note> /// TODO: Add support for caching. /// </note> /// </summary> /// <param name="objectType">The type of object to be serialized.</param> /// <param name="ctx">The serialization context.</param> virtual public ISerializer Build(Type objectType, ISerializationContext ctx) { if (objectType != null) { ISerializer s = null; if (typeof(IICalendar).IsAssignableFrom(objectType)) s = new iCalendarSerializer(); else if (typeof(ICalendarComponent).IsAssignableFrom(objectType)) { if (typeof(IEvent).IsAssignableFrom(objectType)) s = new EventSerializer(); else s = new ComponentSerializer(); } else if (typeof(ICalendarProperty).IsAssignableFrom(objectType)) s = new PropertySerializer(); else if (typeof(ICalendarParameter).IsAssignableFrom(objectType)) s = new ParameterSerializer(); else if (typeof(string).IsAssignableFrom(objectType)) s = new StringSerializer(); // FIXME: remove? //else if (objectType.IsGenericType && typeof(IList<>).IsAssignableFrom(objectType.GetGenericTypeDefinition())) // s = new GenericListSerializer(objectType); else if (objectType.IsEnum) s = new EnumSerializer(objectType); else if (typeof(TimeSpan).IsAssignableFrom(objectType)) s = new TimeSpanSerializer(); else if (typeof(int).IsAssignableFrom(objectType)) s = new IntegerSerializer(); else if (typeof(Uri).IsAssignableFrom(objectType)) s = new UriSerializer(); else if (typeof(ICalendarDataType).IsAssignableFrom(objectType)) s = m_DataTypeSerializerFactory.Build(objectType, ctx); // Default to a string serializer, which simply calls // ToString() on the value to serialize it. else s = new StringSerializer(); // Set the serialization context if (s != null) s.SerializationContext = ctx; return s; } return null; }
/// <summary> /// Serializes the member. /// </summary> /// <param name="context">The context.</param> /// <param name="memberValue">The member value.</param> /// <returns>The deserialized member value.</returns> protected abstract void SerializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue);
/// <summary> /// Deserializes the member. /// </summary> /// <param name="context">The context.</param> /// <param name="memberValue">The member value.</param> /// <returns>The <see cref="SerializationObject" /> representing the deserialized value or result.</returns> protected abstract SerializationObject DeserializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue);
/// <summary> /// Called before the serializer starts deserializing an object. /// </summary> /// <param name="context">The context.</param> protected virtual void BeforeDeserialization(ISerializationContext <TSerializationContext> context) { }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { ConnectionId = reader.ReadInt32(); }
public ImageContent(SerializationContext context) { Context = context; }
TCollection IFactory <TCollection> .Create(ISerializationContext context) => Initialize(default, context);
public override void Serialize(IoBuffer output, ISerializationContext context) { output.PutPascalString(CallId.ToString()); }
public override void Deserialize(IoBuffer input, ISerializationContext context) { Mode = input.GetEnum <MatchmakerNotifyType>(); LotID = input.GetUInt32(); AvatarID = input.GetUInt32(); }
/// <summary> /// Called before the serializer starts serializing a specific member. /// </summary> /// <param name="context">The context.</param> /// <param name="memberValue">The member value.</param> protected virtual void BeforeSerializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue) { }
protected SerializerBase(ISerializationContext ctx) { _mSerializationContext = ctx; }
protected SerializerBase() { _mSerializationContext = Serialization.SerializationContext.Default; }
public abstract void Deserialize(IoBuffer input, ISerializationContext context);
/// <summary> /// Creates a new instance of the <see cref="NestedSerializationContext"/> class. /// </summary> /// <param name="parent">The parent context.</param> /// <param name="offset">The absolute offset at which this stream begins.</param> /// <param name="writer">The writer.</param> public NestedSerializationContext(ISerializationContext parent, int offset, BinaryTokenStreamWriter writer) { this.parentContext = parent; this.initialOffset = offset; this.StreamWriter = writer; }
public OrganizerSerializer(ISerializationContext ctx) : base(ctx) { }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { this.channel = new ChannelInfo(context, reader); Delete = reader.ReadBool(); MakeDefault = reader.ReadBool(); }
/// <summary> /// Called after the serializer has deserialized a specific member. /// </summary> /// <param name="context">The context.</param> /// <param name="memberValue">The member value.</param> protected virtual void AfterDeserializeMember(ISerializationContext <TSerializationContext> context, MemberValue memberValue) { }
public void GetObjectData(ISerializationData dataHolder, ISerializationContext context) { dataHolder.SetValue("SocialExchanges", m_SocialExchanges.ToArray()); }
public void ReadBinary(ISerializationContext context) { }
public static T Deserialize <T>(JsonString jsonString, ISerializationContext context) { return((T)Deserialize(typeof(T), jsonString, context)); }
public EventSerializer(ISerializationContext ctx) : base(ctx) { }
public override void Deserialize(IoBuffer input, ISerializationContext context) { CallId = Guid.Parse(input.GetPascalString()); }
public static void Serializer(object untypedInput, ISerializationContext context, Type expected) { TestTypeA input = (TestTypeA)untypedInput; SerializationManager.SerializeInner(input.Collection, context, typeof(ICollection <TestTypeA>)); }
public void WriteBinary(ISerializationContext context) { }
public override void WritePayload(ISerializationContext context, IValueWriter writer) { writer.WriteInt32(ConnectionId); }
public abstract void Serialize(IoBuffer output, ISerializationContext context);
public CalendarSerializer(ISerializationContext ctx) : base(ctx) { }
public override void Serialize(IoBuffer output, ISerializationContext context) { output.PutEnum(Mode); output.PutUInt32(LotID); output.PutUInt32(AvatarID); }
public static void RecordObject(this ISerializationContext context, object original) { context.RecordObject(original, context.CurrentOffset); }
public override void WritePayload(ISerializationContext context, IValueWriter writer) { this.channel.Serialize(context, writer); writer.WriteBool(Delete); writer.WriteBool(MakeDefault); }
/// <summary> /// Called after the serializer has deserialized an object. /// </summary> /// <param name="context">The context.</param> protected virtual void AfterDeserialization(ISerializationContext <TSerializationContext> context) { }