/// <summary>
        /// 重写相等操作。
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            XmlSerializerCacheKey key = obj as XmlSerializerCacheKey;

            if (key != null &&
                key.Type == this.Type &&
                ArrayEquals(key.KnownTypes, this.KnownTypes))
            {
                return(true);
            }

            return(false);
        }
		public XmlSerializer GetSerializer(Type type, Type[] knownTypes)
		{
			XmlSerializer serializer = null;
			XmlSerializerCacheKey key = new XmlSerializerCacheKey(type, knownTypes);
			if (!_serializers.ContainsKey(key))
			{
				lock (_syncRoot)
				{
					if (!_serializers.ContainsKey(key))
					{
						serializer = knownTypes == null ? new XmlSerializer(type) : new XmlSerializer(type, knownTypes);
						_serializers.Add(key, serializer);
						return serializer;
					}
				}
			}

			serializer = this._serializers[key];
			return serializer;
		}
Exemple #3
0
        public XmlSerializer GetSerializer(Type type, Type[] knownTypes)
        {
            XmlSerializer         serializer = null;
            XmlSerializerCacheKey key        = new XmlSerializerCacheKey(type, knownTypes);

            if (!_serializers.ContainsKey(key))
            {
                lock (_syncRoot)
                {
                    if (!_serializers.ContainsKey(key))
                    {
                        serializer = knownTypes == null ? new XmlSerializer(type) : new XmlSerializer(type, knownTypes);
                        _serializers.Add(key, serializer);
                        return(serializer);
                    }
                }
            }

            serializer = this._serializers[key];
            return(serializer);
        }