本文整理汇总了C#中ISerializationContext类的典型用法代码示例。如果您正苦于以下问题:C# ISerializationContext类的具体用法?C# ISerializationContext怎么用?C# ISerializationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISerializationContext类属于命名空间,在下文中一共展示了ISerializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChannelChangeInfo
public ChannelChangeInfo(ISerializationContext context, IValueReader reader)
{
if (reader == null)
throw new ArgumentNullException("reader");
Deserialize (context, reader);
}
示例2: OnMobileSerializeState
protected override void OnMobileSerializeState(ISerializationContext context)
{
base.OnMobileSerializeState(context);
context.AddState("v", this.Value);
context.AddState("t", this.TypeName);
}
示例3: ReadEntity
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;
}
示例4: SerializeMember
/// <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;
}
}
}
}
示例5: OnMobileDeserializeState
protected override void OnMobileDeserializeState(ISerializationContext context)
{
this.Value = context.GetState<object>("v");
this.TypeName = context.GetState<string>("t");
base.OnMobileDeserializeState(context);
}
示例6: DeserializeMember
/// <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);
}
示例7: ServerInfo
internal ServerInfo(ISerializationContext context, IValueReader reader)
{
if (reader == null)
throw new ArgumentNullException ("reader");
Deserialize (context, reader);
}
示例8: Normalize
public static TextReader Normalize(TextReader tr, ISerializationContext ctx)
{
string s = tr.ReadToEnd();
TextReader reader = Normalize(s, ctx);
tr.Close();
return reader;
}
示例9: ReadPayload
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;
}
示例10: SetObjectData
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;
}
示例11: ReadPayload
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;
}
示例12: WritePayload
public override void WritePayload(ISerializationContext context, IValueWriter writer)
{
using (var ms = new MemoryStream())
{
ScreenFrame.Save(ms, ImageFormat.Png);
writer.WriteBytes(ms.GetBuffer());
}
}
示例13: ReadPayload
public override void ReadPayload (ISerializationContext context, IValueReader reader)
{
if (reader.ReadBool())
SenderId = reader.ReadString();
GroupId = reader.ReadInt32();
Text = reader.ReadString();
}
示例14: WritePayload
public override void WritePayload (ISerializationContext context, IValueWriter writer)
{
if (writer.WriteBool (SenderId != null))
writer.WriteString (SenderId);
writer.WriteInt32 (GroupId);
writer.WriteString (Text);
}
示例15: RegisterId
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);
}
}