Esempio n. 1
0
        /// <summary>
        ///    Creates a deep copy of the current instance.
        /// </summary>
        /// <returns>
        ///    A new <see cref="Frame" /> object identical to the
        ///    current instance.
        /// </returns>
        public override Frame Clone()
        {
            TermsOfUseFrame frame = new TermsOfUseFrame(language, encoding);

            frame.text = text;
            return(frame);
        }
Esempio n. 2
0
        /// <summary>
        ///    Gets a specified terms of use frame from the specified
        ///    tag, trying to to match the language but accepting one
        ///    with a different language if a match was not found.
        /// </summary>
        /// <param name="tag">
        ///    A <see cref="Tag" /> object to search in.
        /// </param>
        /// <param name="language">
        ///    A <see cref="string" /> specifying the ISO-639-2 language
        ///   code to match.
        /// </param>
        /// <returns>
        ///    A <see cref="TermsOfUseFrame" /> object containing the
        ///    matching frame, or <see langword="null" /> if a match
        ///    wasn't found.
        /// </returns>
        public static TermsOfUseFrame GetPreferred(Tag tag,
                                                   string language)
        {
            TermsOfUseFrame best = null;

            foreach (Frame f in tag.GetFrames(FrameType.USER))
            {
                TermsOfUseFrame cf = f as TermsOfUseFrame;
                if (cf == null)
                {
                    continue;
                }

                if (cf.Language == language)
                {
                    return(cf);
                }

                if (best == null)
                {
                    best = cf;
                }
            }

            return(best);
        }
Esempio n. 3
0
        /// <summary>
        ///    Creates a deep copy of the current instance.
        /// </summary>
        /// <returns>
        ///    A new <see cref="Frame" /> object identical to the
        ///    current instance.
        /// </returns>
        public override Frame Clone()
        {
            var frame = new TermsOfUseFrame(language, TextEncoding)
            {
                Text = Text
            };

            return(frame);
        }
Esempio n. 4
0
        /// <summary>
        ///    Gets a specified terms of use frame from the specified
        ///    tag, optionally creating it if it does not exist.
        /// </summary>
        /// <param name="tag">
        ///    A <see cref="Tag" /> object to search in.
        /// </param>
        /// <param name="language">
        ///    A <see cref="string" /> specifying the ISO-639-2 language
        ///   code to match.
        /// </param>
        /// <param name="create">
        ///    A <see cref="bool" /> specifying whether or not to create
        ///    and add a new frame to the tag if a match is not found.
        /// </param>
        /// <returns>
        ///    A <see cref="TermsOfUseFrame" /> object containing the
        ///    matching frame, or <see langword="null" /> if a match
        ///    wasn't found and <paramref name="create" /> is <see
        ///    langword="false" />.
        /// </returns>
        public static TermsOfUseFrame Get(Tag tag, string language, bool create)
        {
            foreach (Frame f in tag.GetFrames(FrameType.USER))
            {
                if (f is TermsOfUseFrame cf && (language == null || language == cf.Language))
                {
                    return(cf);
                }
            }

            if (!create)
            {
                return(null);
            }

            var frame = new TermsOfUseFrame(language);

            tag.AddFrame(frame);
            return(frame);
        }