Exemplo n.º 1
0
        /// <summary>
        ///     Registers all serialization surrogates defined in this assembly with the specified formatter.
        /// </summary>
        /// <typeparam name="TFormatter"> The type of formatter to register for. </typeparam>
        /// <param name="formatter"> The formatter to register for.</param>
        /// <returns> An instance of the formatter. </returns>
        public static TFormatter IncludeId3SerializationSupport <TFormatter>(this TFormatter formatter)
            where TFormatter : IFormatter
        {
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            var selector = new SurrogateSelector();

            //Id3Tag
            selector.AddSurrogate(typeof(Id3Tag), new StreamingContext(StreamingContextStates.All),
                                  new Id3TagSurrogate());

            //TextFrame-derived classes
            selector.AddFrameSurrogates <TextFrameSurrogate>(
                typeof(AlbumFrame),
                typeof(BandFrame),
                typeof(ConductorFrame),
                typeof(ContentGroupDescriptionFrame),
                typeof(CopyrightFrame),
                typeof(CustomTextFrame),
                typeof(EncoderFrame),
                typeof(EncodingSettingsFrame),
                typeof(FileOwnerFrame),
                typeof(GenreFrame),
                typeof(PublisherFrame),
                typeof(SubtitleFrame),
                typeof(TitleFrame)
                );

            //NumericFrame-derived classes
            selector.AddFrameSurrogates <TextFrameSurrogate>(
                typeof(BeatsPerMinuteFrame),
                typeof(YearFrame)
                );

            //DateTimeFrame-derived classes
            selector.AddFrameSurrogates <TextFrameSurrogate>(typeof(RecordingDateFrame));

            //ListTextFrame-derived classes
            selector.AddFrameSurrogates <TextFrameSurrogate>(
                typeof(ArtistsFrame),
                typeof(ComposersFrame),
                typeof(LyricistsFrame)
                );

            //Other TextFrameBase<>-derived classes
            selector.AddFrameSurrogates <TextFrameSurrogate>(
                typeof(FileTypeFrame),
                typeof(LengthFrame),
                typeof(TrackFrame)
                );

            //UrlLinkFrame-derived classes
            selector.AddFrameSurrogates <UrlLinkFrameSurrogate>(
                typeof(ArtistUrlFrame),
                typeof(AudioFileUrlFrame),
                typeof(AudioSourceUrlFrame),
                typeof(CommercialUrlFrame),
                typeof(CopyrightUrlFrame),
                typeof(CustomUrlLinkFrame),
                typeof(PaymentUrlFrame)
                );

            //All other frames
            selector.AddFrameSurrogate <CommentFrame, CommentFrameSurrogate>();
            selector.AddFrameSurrogate <LyricsFrame, LyricsFrameSurrogate>();
            selector.AddFrameSurrogate <PictureFrame, PictureFrameSurrogate>();
            selector.AddFrameSurrogate <PrivateFrame, PrivateFrameSurrogate>();
            selector.AddFrameSurrogate <UnknownFrame, UnknownFrameSurrogate>();

            formatter.SurrogateSelector = selector;
            return(formatter);
        }