using System; using System.ComponentModel; using ProtoBuf.Meta; #if FEAT_IKVM using Type = IKVM.Reflection.Type; using IKVM.Reflection; #else using System.Reflection; #endif namespace ProtoBuf { /// /// 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. /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)] public sealed class ProtoIncludeAttribute : Attribute { /// /// Creates a new instance of the ProtoIncludeAttribute. /// /// The unique index (within the type) that will identify this data. /// The additional type to serialize/deserialize. public ProtoIncludeAttribute(int tag, System.Type knownType) : this(tag, knownType == null ? "" : knownType.AssemblyQualifiedName) { } /// /// Creates a new instance of the ProtoIncludeAttribute. /// /// The unique index (within the type) that will identify this data. /// The additional type to serialize/deserialize. 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"); this.tag = tag; this.knownTypeName = knownTypeName; } /// /// Gets the unique index (within the type) that will identify this data. /// public int Tag { get { return tag; } } private readonly int tag; /// /// Gets the additional type to serialize/deserialize. /// public string KnownTypeName { get { return knownTypeName; } } private readonly string knownTypeName; /// /// Gets the additional type to serialize/deserialize. /// public Type KnownType { get { return TypeModel.ResolveKnownType(KnownTypeName, null, null); } } /// /// Specifies whether the inherited sype's sub-message should be /// written with a length-prefix (default), or with group markers. /// [DefaultValue(DataFormat.Default)] public DataFormat DataFormat { get { return dataFormat; } set { dataFormat = value; } } private DataFormat dataFormat = DataFormat.Default; } }