Example #1
0
        /// <summary>
        /// Register (add) a type handler for a type and dbType
        /// </summary>
        /// <param name="type">the type</param>
        /// <param name="dbType">the dbType (optional, if dbType is null the handler will be used for all dbTypes)</param>
        /// <param name="handler">the handler instance</param>
        public void Register(Type type, string dbType, ITypeHandler handler)
        {
            IDictionary <string, ITypeHandler> map = null;

            typeHandlerMap.TryGetValue(type, out map);
            if (map == null)
            {
                map = new Dictionary <string, ITypeHandler>();
                typeHandlerMap.Add(type, map);
            }
            if (dbType == null)
            {
                if (logger.IsInfoEnabled)
                {
                    // notify the user that they are no longer using one of the built-in type handlers
                    ITypeHandler oldTypeHandler = null;
                    map.TryGetValue(NULL, out oldTypeHandler);

                    if (oldTypeHandler != null)
                    {
                        // the replacement will always(?) be a CustomTypeHandler
                        CustomTypeHandler customTypeHandler = handler as CustomTypeHandler;

                        string replacement = string.Empty;

                        if (customTypeHandler != null)
                        {
                            // report the underlying type
                            replacement = customTypeHandler.Callback.ToString();
                        }
                        else
                        {
                            replacement = handler.ToString();
                        }

                        // should oldTypeHandler be checked if its a CustomTypeHandler and if so report the Callback property ???
                        logger.Info("Replacing type handler [" + oldTypeHandler + "] with [" + replacement + "].");
                    }
                }

                map[NULL] = handler;
            }
            else
            {
                map.Add(dbType, handler);
            }
        }
Example #2
0
        /// <summary>
        /// Register (add) a type handler for a type and dbType
        /// </summary>
        /// <param name="type">the type</param>
        /// <param name="dbType">the dbType (optional, if dbType is null the handler will be used for all dbTypes)</param>
        /// <param name="handler">the handler instance</param>
        public void Register(Type type, string dbType, ITypeHandler handler)
        {
            HybridDictionary map = (HybridDictionary)_typeHandlerMap[type];

            if (map == null)
            {
                map = new HybridDictionary();
                _typeHandlerMap.Add(type, map);
            }
            if (dbType == null)
            {
                if (_logger.IsDebugEnabled)
                {
                    // notify the user that they are no longer using one of the built-in type handlers
                    ITypeHandler oldTypeHandler = (ITypeHandler)map[NULL];

                    if (oldTypeHandler != null)
                    {
                        // the replacement will always(?) be a CustomTypeHandler
                        CustomTypeHandler customTypeHandler = handler as CustomTypeHandler;

                        string replacement = string.Empty;

                        if (customTypeHandler != null)
                        {
                            // report the underlying type
                            replacement = customTypeHandler.Callback.ToString();
                        }
                        else
                        {
                            replacement = handler.ToString();
                        }

                        // should oldTypeHandler be checked if its a CustomTypeHandler and if so report the Callback property ???
                        _logger.Debug("Replacing type handler [" + oldTypeHandler.ToString() + "] with [" + replacement + "].");
                    }
                }

                map[NULL] = handler;
            }
            else
            {
                map.Add(dbType, handler);
            }
        }
        public void Register(Type type, string dbType, ITypeHandler handler)
        {
            HybridDictionary dictionary = (HybridDictionary)this._typeHandlerMap[type];

            if (dictionary == null)
            {
                dictionary = new HybridDictionary();
                this._typeHandlerMap.Add(type, dictionary);
            }
            if (dbType == null)
            {
                if (_logger.IsInfoEnabled)
                {
                    ITypeHandler handler2 = (ITypeHandler)dictionary["_NULL_TYPE_"];
                    if (handler2 != null)
                    {
                        CustomTypeHandler handler3 = handler as CustomTypeHandler;
                        string            str      = string.Empty;
                        if (handler3 != null)
                        {
                            str = handler3.Callback.ToString();
                        }
                        else
                        {
                            str = handler.ToString();
                        }
                        _logger.Info("Replacing type handler [" + handler2.ToString() + "] with [" + str + "].");
                    }
                }
                dictionary["_NULL_TYPE_"] = handler;
            }
            else
            {
                dictionary.Add(dbType, handler);
            }
        }
        /// <summary>
        /// Register (add) a type handler for a type and dbType
        /// </summary>
        /// <param name="type">the type</param>
        /// <param name="dbType">the dbType (optional, if dbType is null the handler will be used for all dbTypes)</param>
        /// <param name="handler">the handler instance</param>
        public void Register(Type type, string dbType, ITypeHandler handler)
        {
            HybridDictionary map = (HybridDictionary)_typeHandlerMap[type];
            if (map == null)
            {
                map = new HybridDictionary();
                _typeHandlerMap.Add(type, map);
            }
            if (dbType == null)
            {
                if (_logger.IsInfoEnabled)
                {
                    // notify the user that they are no longer using one of the built-in type handlers
                    ITypeHandler oldTypeHandler = (ITypeHandler)map[NULL];

                    if (oldTypeHandler != null)
                    {
                        // the replacement will always(?) be a CustomTypeHandler
                        CustomTypeHandler customTypeHandler = handler as CustomTypeHandler;

                        string replacement = string.Empty;

                        if (customTypeHandler != null)
                        {
                            // report the underlying type
                            replacement = customTypeHandler.Callback.ToString();
                        }
                        else
                        {
                            replacement = handler.ToString();
                        }

                        // should oldTypeHandler be checked if its a CustomTypeHandler and if so report the Callback property ???
                        _logger.Info("Replacing type handler [" + oldTypeHandler.ToString() + "] with [" + replacement + "].");
                    }
                }

                map[NULL] = handler;
            }
            else
            {
                map.Add(dbType, handler);
            }
        }
Example #5
0
		/// <summary>
		/// Register (add) a type handler for a type and dbType
        /// 根据前两个参数 分两次获取数据 最后把dbType加入字典当中
		/// </summary>
		/// <param name="type">the type</param>
		/// <param name="dbType">the dbType (optional, if dbType is null the handler will be used for all dbTypes)</param>
		/// <param name="handler">the handler instance</param>
		public void Register(Type type, string dbType, ITypeHandler handler) 
		{
            IDictionary<string, ITypeHandler> map = null;
            typeHandlerMap.TryGetValue(type, out map);
			if (map == null) //如果type不存在,则加入当前对象
			{
                map = new Dictionary<string, ITypeHandler>();
				typeHandlerMap.Add(type, map)  ;
			}
			if (dbType==null)
			{
				if (logger.IsInfoEnabled)
				{
					// notify the user that they are no longer using one of the built-in type handlers
                    ITypeHandler oldTypeHandler = null;
                    map.TryGetValue(NULL, out oldTypeHandler);

					if (oldTypeHandler != null)
					{
						// the replacement will always(?) be a CustomTypeHandler
						CustomTypeHandler customTypeHandler = handler as CustomTypeHandler;
						
						string replacement = string.Empty;
						
						if (customTypeHandler != null)
						{
							// report the underlying type
							replacement = customTypeHandler.Callback.ToString();
						}
						else
						{
							replacement = handler.ToString();
						}

						// should oldTypeHandler be checked if its a CustomTypeHandler and if so report the Callback property ???
						logger.Info("Replacing type handler [" + oldTypeHandler + "] with [" + replacement + "].");
					}
				}

                map[NULL] = handler;//意味着dbType默认的null类型 对应当前
			}
			else
			{
                map.Add(dbType, handler);//最后加入字典当中ITypeHandler处理类对象
			}
		}