Пример #1
0
        public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream)
        {
            SecurityHelper.DemandPlugInSerializerPermissions();

            SerializerWriter serializerWriter = null;

            if (serializerDescriptor == null)
            {
                throw new ArgumentNullException("serializerDescriptor");
            }

            string serializerKey = serializerDescriptor.DisplayName + "/" + serializerDescriptor.AssemblyName + "/" + serializerDescriptor.AssemblyVersion + "/" + serializerDescriptor.WinFXVersion;

            if (!serializerDescriptor.IsLoadable)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderWrongVersion), serializerKey);
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            bool found = false;

            foreach (SerializerDescriptor sd in InstalledSerializers)
            {
                if (sd.Equals(serializerDescriptor))
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderUnknownSerializer), serializerKey);
            }

            try
            {
                ISerializerFactory factory = serializerDescriptor.CreateSerializerFactory();

                serializerWriter = factory.CreateSerializerWriter(stream);
            }
            catch (FileNotFoundException)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName);
            }
            catch (FileLoadException)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName);
            }
            catch (BadImageFormatException)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName);
            }
            catch (MissingMethodException)
            {
                throw new ArgumentException(SR.Get(SRID.SerializerProviderCannotLoad), serializerDescriptor.DisplayName);
            }

            return(serializerWriter);
        }
        public SerializerWriter CreateSerializerWriter(SerializerDescriptor serializerDescriptor, Stream stream)
        {
            SecurityHelper.DemandPlugInSerializerPermissions();
            SerializerWriter result = null;

            if (serializerDescriptor == null)
            {
                throw new ArgumentNullException("serializerDescriptor");
            }
            string paramName = string.Concat(new object[]
            {
                serializerDescriptor.DisplayName,
                "/",
                serializerDescriptor.AssemblyName,
                "/",
                serializerDescriptor.AssemblyVersion,
                "/",
                serializerDescriptor.WinFXVersion
            });

            if (!serializerDescriptor.IsLoadable)
            {
                throw new ArgumentException(SR.Get("SerializerProviderWrongVersion"), paramName);
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            bool flag = false;

            foreach (SerializerDescriptor serializerDescriptor2 in this.InstalledSerializers)
            {
                if (serializerDescriptor2.Equals(serializerDescriptor))
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                throw new ArgumentException(SR.Get("SerializerProviderUnknownSerializer"), paramName);
            }
            try
            {
                ISerializerFactory serializerFactory = serializerDescriptor.CreateSerializerFactory();
                result = serializerFactory.CreateSerializerWriter(stream);
            }
            catch (FileNotFoundException)
            {
                throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName);
            }
            catch (FileLoadException)
            {
                throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName);
            }
            catch (BadImageFormatException)
            {
                throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName);
            }
            catch (MissingMethodException)
            {
                throw new ArgumentException(SR.Get("SerializerProviderCannotLoad"), serializerDescriptor.DisplayName);
            }
            return(result);
        }