public static UrlLinkFrame Get(Tag tag, ByteVector ident, bool create) { if (tag == null) { throw new ArgumentNullException("tag"); } if (ident == null) { throw new ArgumentNullException("ident"); } if (ident.Count != 4) { throw new ArgumentException("Identifier must be four bytes long.", "ident"); } foreach (UrlLinkFrame frame in tag.GetFrames <UrlLinkFrame>(ident)) { return(frame); } if (!create) { return(null); } UrlLinkFrame new_frame = new UrlLinkFrame(ident); tag.AddFrame(new_frame); return(new_frame); }
public override Frame Clone() { UrlLinkFrame frame = (this is UserUrlLinkFrame)?new UserUrlLinkFrame(null, encoding):new UrlLinkFrame(FrameId); frame.text_fields = (string[])text_fields.Clone(); if (raw_data != null) { frame.raw_data = new ByteVector(raw_data); } frame.raw_version = raw_version; return(frame); }
public string GetTextAsString(ByteVector ident) { Frame frame; if (ident[0] == 'W') { frame = UrlLinkFrame.Get(this, ident, false); } else { frame = TextInformationFrame.Get(this, ident, false); } string result = frame == null?null:frame.ToString(); return(string.IsNullOrEmpty(result)?null:result); }
public void SetTextFrame(ByteVector ident, params string[] text) { if (ident == null) { throw new ArgumentNullException("ident"); } if (ident.Count != 4) { throw new ArgumentException("Identifier must be four bytes long.", "ident"); } bool empty = true; if (text != null) { for (int i = 0; empty && i < text.Length; i++) { if (!string.IsNullOrEmpty(text[i])) { empty = false; } } } if (empty) { RemoveFrames(ident); return; } if (ident[0] == 'W') { UrlLinkFrame urlFrame = UrlLinkFrame.Get(this, ident, true); urlFrame.Text = text; urlFrame.TextEncoding = DefaultEncoding; return; } TextInformationFrame frame = TextInformationFrame.Get(this, ident, true); frame.Text = text; frame.TextEncoding = DefaultEncoding; }
/// <summary> /// Gets a <see cref="UrlLinkFrame" /> object of a /// specified type from a specified tag, optionally creating /// and adding one with a specified encoding if none is /// found. /// </summary> /// <param name="tag"> /// A <see cref="Tag" /> object to search for the specified /// tag in. /// </param> /// <param name="ident"> /// A <see cref="ByteVector" /> object containing the frame /// identifer to search for. /// </param> /// <param name="encoding"> /// A <see cref="StringType" /> value specifying the encoding /// to use if a new frame is created. /// </param> /// <param name="create"> /// A <see cref="bool" /> value specifying whether or not to /// create a new frame if an existing frame was not found. /// </param> /// <returns> /// A <see cref="UrlLinkFrame" /> object containing /// the frame found in or added to <paramref name="tag" /> or /// <see langword="null" /> if no value was found <paramref /// name="create" /> is <see langword="false" />. /// </returns> /// <remarks> /// To create a frame without having to specify the encoding, /// use <see cref="Get(Tag,ByteVector,bool)" />. /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="tag" /> or <paramref name="type" /> is /// <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="type" /> is not exactly four bytes long. /// </exception> public static UrlLinkFrame Get(Tag tag, ByteVector ident, StringType encoding, bool create) { if (tag == null) throw new ArgumentNullException("tag"); if (ident == null) throw new ArgumentNullException("ident"); if (ident.Count != 4) throw new ArgumentException( "Identifier must be four bytes long.", "ident"); foreach (UrlLinkFrame frame in tag.GetFrames<UrlLinkFrame>(ident)) return frame; if (!create) return null; UrlLinkFrame new_frame = new UrlLinkFrame(ident, encoding); tag.AddFrame(new_frame); return new_frame; }