Quasar/Server/Core/ProtoBuf/ProtoIncludeAttribute.cs

88 lines
3.0 KiB
C#
Raw Normal View History

2014-07-08 05:58:53 -07:00
using System;
using System.ComponentModel;
using ProtoBuf.Meta;
#if FEAT_IKVM
using Type = IKVM.Reflection.Type;
using IKVM.Reflection;
#else
using System.Reflection;
2014-07-08 05:58:53 -07:00
#endif
2014-07-08 05:58:53 -07:00
namespace ProtoBuf
{
/// <summary>
/// Indicates the known-types to support for an individual
/// message. This serializes each level in the hierarchy as
/// a nested message to retain wire-compatibility with
/// other protocol-buffer implementations.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
public sealed class ProtoIncludeAttribute : Attribute
{
///<summary>
/// Creates a new instance of the ProtoIncludeAttribute.
/// </summary>
/// <param name="tag">The unique index (within the type) that will identify this data.</param>
/// <param name="knownType">The additional type to serialize/deserialize.</param>
public ProtoIncludeAttribute(int tag, System.Type knownType)
: this(tag, knownType == null ? "" : knownType.AssemblyQualifiedName)
{
}
2014-07-08 05:58:53 -07:00
/// <summary>
/// Creates a new instance of the ProtoIncludeAttribute.
/// </summary>
/// <param name="tag">The unique index (within the type) that will identify this data.</param>
/// <param name="knownTypeName">The additional type to serialize/deserialize.</param>
public ProtoIncludeAttribute(int tag, string knownTypeName)
{
if (tag <= 0) throw new ArgumentOutOfRangeException("tag", "Tags must be positive integers");
if (Helpers.IsNullOrEmpty(knownTypeName))
throw new ArgumentNullException("knownTypeName", "Known type cannot be blank");
2014-07-08 05:58:53 -07:00
this.tag = tag;
this.knownTypeName = knownTypeName;
}
/// <summary>
/// Gets the unique index (within the type) that will identify this data.
/// </summary>
public int Tag
{
get { return tag; }
}
2014-07-08 05:58:53 -07:00
private readonly int tag;
/// <summary>
/// Gets the additional type to serialize/deserialize.
/// </summary>
public string KnownTypeName
{
get { return knownTypeName; }
}
2014-07-08 05:58:53 -07:00
private readonly string knownTypeName;
/// <summary>
/// Gets the additional type to serialize/deserialize.
/// </summary>
public Type KnownType
{
get { return TypeModel.ResolveKnownType(KnownTypeName, null, null); }
2014-07-08 05:58:53 -07:00
}
/// <summary>
/// Specifies whether the inherited sype's sub-message should be
/// written with a length-prefix (default), or with group markers.
/// </summary>
[DefaultValue(DataFormat.Default)]
public DataFormat DataFormat
{
get { return dataFormat; }
set { dataFormat = value; }
}
2014-07-08 05:58:53 -07:00
private DataFormat dataFormat = DataFormat.Default;
}
}