Ejemplo n.º 1
0
        /// <summary>
        /// Load archive of specified type from stream.
        /// </summary>
        /// <param name="stream">Stream to read from.</param>
        /// <param name="flags">Flags for loader.</param>
        /// <returns>BA2Archive instance.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <c>stream</c> is null.</exception>
        /// <exception cref="BA2LoadException" />
        public static T Load <T>(Stream stream, BA2LoaderFlags flags = BA2LoaderFlags.None) where T : BA2Archive
        {
            BA2Archive archive      = Load(stream, flags);
            Type       exceptedType = typeof(T);

            var exceptedArchive = archive as T;

            if (exceptedArchive != null)
            {
                return(exceptedArchive);
            }
            else
            {
                if (archive != null)
                {
                    archive.Dispose();
                }

                throw new BA2LoadException(
                          string.Format("Loaded archive has type {0}, which is not same as requested type {1}",
                                        GetArchiveType(archive),
                                        GetArchiveType <T>()));
            }
        }