/// <summary> /// Serializes a tag reference. /// </summary> /// <param name="context">The serialization context to use.</param> /// <param name="block">The block to write to.</param> /// <param name="referencedTag">The referenced tag.</param> /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param> private void SerializeTagReference(ISerializationContext context, IDataBlock block, CachedTag referencedTag, TagFieldAttribute valueInfo) { if (referencedTag != null && referencedTag.Group == TagGroup.None) { referencedTag = null; } if (referencedTag != null && valueInfo != null && valueInfo.ValidTags != null) { foreach (string tag in valueInfo.ValidTags) { if (!referencedTag.IsInGroup(tag)) { throw new Exception($"Invalid group for tag reference: {referencedTag.Group.Tag}"); } } } block.AddTagReference(referencedTag, valueInfo == null ? false : valueInfo.Flags.HasFlag(Short)); if (valueInfo == null || !valueInfo.Flags.HasFlag(Short)) { block.Writer.Write((referencedTag != null) ? referencedTag.Group.Tag.Value : -1); block.Writer.Write(0); block.Writer.Write(0); } block.Writer.Write((referencedTag != null) ? referencedTag.Index : -1); }
/// <summary> /// Serializes a tag reference. /// </summary> /// <param name="context">The serialization context to use.</param> /// <param name="block">The block to write to.</param> /// <param name="referencedTag">The referenced tag.</param> /// <param name="valueInfo">Information about the value. Can be <c>null</c>.</param> private void SerializeTagReference(ISerializationContext context, IDataBlock block, CachedTagInstance referencedTag, TagFieldAttribute valueInfo) { if ((referencedTag?.Index ?? 0) == -1) { referencedTag = context.GetTagByName(referencedTag.Group, referencedTag.Name); } if (referencedTag != null && valueInfo != null && valueInfo.ValidTags != null) { foreach (string tag in valueInfo.ValidTags) { if (!referencedTag.IsInGroup(tag)) { throw new Exception($"Invalid group for tag reference: {referencedTag.Group.Tag}"); } } } block.AddTagReference(referencedTag); if (valueInfo == null || !valueInfo.Flags.HasFlag(Short)) { block.Writer.Write((referencedTag != null) ? referencedTag.Group.Tag.Value : -1); block.Writer.Write(0); block.Writer.Write(0); } block.Writer.Write((referencedTag != null) ? referencedTag.Index : -1); }