本文整理汇总了C#中ProtoBuf.ProtoWriter.GetTypeKey方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoWriter.GetTypeKey方法的具体用法?C# ProtoWriter.GetTypeKey怎么用?C# ProtoWriter.GetTypeKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.ProtoWriter
的用法示例。
在下文中一共展示了ProtoWriter.GetTypeKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteNetObject
/// <summary>
/// Writes an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static void WriteNetObject(object value, ProtoWriter dest, int key, NetObjectOptions options)
{
Helpers.DebugAssert(value != null);
bool dynamicType = (options & NetObjectOptions.DynamicType) != 0,
asReference = (options & NetObjectOptions.AsReference) != 0;
WireType wireType = dest.WireType;
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
bool writeObject = true;
if (asReference)
{
bool existing;
int objectKey = dest.NetCache.AddObjectKey(value, out existing);
ProtoWriter.WriteFieldHeader(existing ? FieldExistingObjectKey : FieldNewObjectKey, WireType.Variant, dest);
ProtoWriter.WriteInt32(objectKey, dest);
if (existing)
{
writeObject = false;
}
}
if (writeObject)
{
if (dynamicType)
{
bool existing;
Type type = value.GetType();
key = dest.GetTypeKey(ref type);
int typeKey = dest.NetCache.AddObjectKey(type, out existing);
ProtoWriter.WriteFieldHeader(existing ? FieldExistingTypeKey : FieldNewTypeKey, WireType.Variant, dest);
ProtoWriter.WriteInt32(typeKey, dest);
if (!existing)
{
ProtoWriter.WriteFieldHeader(FieldTypeName, WireType.String, dest);
ProtoWriter.WriteString(dest.SerializeType(type), dest);
}
}
ProtoWriter.WriteFieldHeader(FieldObject, wireType, dest);
if (value is string)
{
ProtoWriter.WriteString((string)value, dest);
}
else {
ProtoWriter.WriteObject(value, key, dest);
}
}
ProtoWriter.EndSubItem(token, dest);
}
示例2: WriteNetObject
/// <summary>
/// Writes an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static void WriteNetObject(object value, ProtoWriter dest, int key, NetObjectOptions options)
{
#if FEAT_IKVM
throw new NotSupportedException();
#else
if (dest == null) throw new ArgumentNullException("dest");
bool dynamicType = (options & NetObjectOptions.DynamicType) != 0,
asReference = (options & NetObjectOptions.AsReference) != 0;
WireType wireType = dest.WireType;
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
bool writeObject = true;
if (asReference)
{
bool existing;
int objectKey = dest.NetCache.AddObjectKey(value, out existing);
ProtoWriter.WriteFieldHeader(existing ? FieldExistingObjectKey : FieldNewObjectKey, WireType.Variant, dest);
ProtoWriter.WriteInt32(objectKey, dest);
if (existing)
{
writeObject = false;
}
}
if (writeObject)
{
if (dynamicType)
{
bool existing;
Type type = value.GetType();
if (!(value is string))
{
key = dest.GetTypeKey(ref type);
if (key < 0) throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
int typeKey = dest.NetCache.AddObjectKey(type, out existing);
ProtoWriter.WriteFieldHeader(existing ? FieldExistingTypeKey : FieldNewTypeKey, WireType.Variant, dest);
ProtoWriter.WriteInt32(typeKey, dest);
if (!existing)
{
ProtoWriter.WriteFieldHeader(FieldTypeName, WireType.String, dest);
ProtoWriter.WriteString(dest.SerializeType(type), dest);
}
}
ProtoWriter.WriteFieldHeader(FieldObject, wireType, dest);
if (value is string)
{
ProtoWriter.WriteString((string)value, dest);
}
else {
ProtoWriter.WriteObject(value, key, dest);
}
}
ProtoWriter.EndSubItem(token, dest);
#endif
}
示例3: WriteNetObject
public static void WriteNetObject(object value, ProtoWriter dest, int key, BclHelpers.NetObjectOptions options)
{
if (dest == null)
{
throw new ArgumentNullException("dest");
}
bool flag = (byte)(options & BclHelpers.NetObjectOptions.DynamicType) != 0;
bool flag2 = (byte)(options & BclHelpers.NetObjectOptions.AsReference) != 0;
WireType wireType = dest.WireType;
SubItemToken token = ProtoWriter.StartSubItem(null, dest);
bool flag3 = true;
if (flag2)
{
bool flag4;
int value2 = dest.NetCache.AddObjectKey(value, out flag4);
ProtoWriter.WriteFieldHeader((!flag4) ? 2 : 1, WireType.Variant, dest);
ProtoWriter.WriteInt32(value2, dest);
if (flag4)
{
flag3 = false;
}
}
if (flag3)
{
if (flag)
{
Type type = value.GetType();
if (!(value is string))
{
key = dest.GetTypeKey(ref type);
if (key < 0)
{
throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
}
bool flag5;
int value3 = dest.NetCache.AddObjectKey(type, out flag5);
ProtoWriter.WriteFieldHeader((!flag5) ? 4 : 3, WireType.Variant, dest);
ProtoWriter.WriteInt32(value3, dest);
if (!flag5)
{
ProtoWriter.WriteFieldHeader(8, WireType.String, dest);
ProtoWriter.WriteString(dest.SerializeType(type), dest);
}
}
ProtoWriter.WriteFieldHeader(10, wireType, dest);
if (value is string)
{
ProtoWriter.WriteString((string)value, dest);
}
else
{
ProtoWriter.WriteObject(value, key, dest);
}
}
ProtoWriter.EndSubItem(token, dest);
}