Ejemplo n.º 1
0
        /// <summary>
        /// Gets the SerializableType for the specified Type
        /// </summary>
        /// <param name="serializableType">The Type that will be Serialized to the database.</param>
        /// <returns>A SerializableType</returns>
        /// <remarks>
        /// <para>
        /// In addition to returning the SerializableType it will also ensure that it has
        /// been added to the basicNameMap with the keys <c>Type.FullName</c> (the result
        /// of <c>IType.Name</c> and <c>Type.AssemblyQualifiedName</c>.  This is different
        /// from the other items put in the basicNameMap because it is uses the AQN and the
        /// FQN as opposed to the short name used in the maps and the FQN.
        /// </para>
        /// </remarks>
        public static NullableType GetSerializableType(System.Type serializableType)
        {
            var key = serializableType.AssemblyQualifiedName;

            // The value factory may be run concurrently, but only one resulting value will be yielded to all threads.
            // So we should add the type with its other key in a later operation in order to ensure we cache the same
            // instance for both keys.
            var added = false;
            var type  = (NullableType)typeByTypeOfName.GetOrAdd(
                key,
                k =>
            {
                var returnType = new SerializableType(serializableType);
                added          = true;
                return(returnType);
            });

            if (added && typeByTypeOfName.GetOrAdd(type.Name, type) != type)
            {
                throw new HibernateException($"Another item with the key {type.Name} has already been added to typeByTypeOfName.");
            }

            return(type);
        }
		public static NullableType GetSerializableType(int length)
		{
			string key = GetKeyForLengthBased(NHibernateUtil.Serializable.Name, length);

			IType returnType;
			if (!typeByTypeOfName.TryGetValue(key, out returnType))
			{
				returnType = new SerializableType(typeof(object), SqlTypeFactory.GetBinary(length));
				AddToTypeOfNameWithLength(key, returnType);
			}

			return (NullableType)returnType;
		}
		public static NullableType GetSerializableType(System.Type serializableType, int length)
		{
			string key = GetKeyForLengthBased(serializableType.AssemblyQualifiedName, length);

			IType returnType;
			if (!typeByTypeOfName.TryGetValue(key, out returnType))
			{
				returnType = new SerializableType(serializableType, SqlTypeFactory.GetBinary(length));
				AddToTypeOfNameWithLength(key, returnType);
			}

			return (NullableType)returnType;
		}
		public static NullableType GetSerializableType(System.Type serializableType)
		{
			string key = serializableType.AssemblyQualifiedName;

			IType returnType;
			if (!typeByTypeOfName.TryGetValue(key, out returnType))
			{
				returnType = new SerializableType(serializableType);
				AddToTypeOfName(key, returnType);
			}

			return (NullableType)returnType;
		}
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static NullableType GetSerializableType(int length)
        {
            string key = GetKeyForLengthBased(NHibernateUtil.Serializable.Name, length);

            NullableType returnType = (NullableType) typeByTypeOfName[key];
            if (returnType == null)
            {
                returnType = new SerializableType(typeof(object), SqlTypeFactory.GetBinary(length));
                AddToTypeOfNameWithLength(key, returnType);
            }

            return returnType;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="serializableType"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static NullableType GetSerializableType(System.Type serializableType, int length)
        {
            string key = GetKeyForLengthBased(serializableType.AssemblyQualifiedName, length);

            NullableType returnType = (NullableType) typeByTypeOfName[key];
            if (returnType == null)
            {
                returnType = new SerializableType(serializableType, SqlTypeFactory.GetBinary(length));
                AddToTypeOfNameWithLength(key, returnType);
            }

            return returnType;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the SerializableType for the specified Type
        /// </summary>
        /// <param name="serializableType">The Type that will be Serialized to the database.</param>
        /// <returns>A SerializableType</returns>
        /// <remarks>
        /// <para>
        /// In addition to returning the SerializableType it will also ensure that it has
        /// been added to the basicNameMap with the keys <c>Type.FullName</c> (the result
        /// of <c>IType.Name</c> and <c>Type.AssemblyQualifiedName</c>.  This is different 
        /// from the other items put in the basicNameMap because it is uses the AQN and the
        /// FQN as opposed to the short name used in the maps and the FQN.
        /// </para>
        /// <para>
        /// Since this method calls the method
        /// <see cref="GetSerializableType(System.Type, Int32)">GetSerializableType(System.Type, Int32)</see>
        /// with the default length, those keys will also be added.
        /// </para>
        /// </remarks>
        public static NullableType GetSerializableType(System.Type serializableType)
        {
            string key = serializableType.AssemblyQualifiedName;

            NullableType returnType = (NullableType) typeByTypeOfName[key];
            if (returnType == null)
            {
                returnType = new SerializableType(serializableType);
                AddToTypeOfName(key, returnType);
            }

            return returnType;
        }