Пример #1
0
 /// <summary> 初始化 DictionaryEx 设定getValue委托,key不存在时执行委托,并加入集合
 /// </summary>
 /// <param name="getValue">获取值的委托</param>
 /// <param name="comparer">比较键时要使用对象,如果为null则使用默认比较方法</param>
 public DictionaryEx(Converter <TKey, TValue> getValue, IEqualityComparer <TKey> comparer)
 {
     Assertor.AreNull(getValue, "getValue");
     _items    = new Dictionary <TKey, TValue>(comparer);
     _getValue = getValue;
     _mode     = 2;
 }
Пример #2
0
 /// <summary> 初始化 DictionaryEx 只读集合
 /// </summary>
 /// <param name="dictionary">内部字典</param>
 public DictionaryEx(IDictionary <TKey, TValue> dictionary)
 {
     Assertor.AreNull(dictionary, "dictionary");
     IsReadOnly = true;
     _items     = dictionary;
     _mode      = 0;
 }
Пример #3
0
 /// <summary> 初始化 DictionaryEx 设定getValue委托,key不存在时执行委托,并加入集合
 /// </summary>
 /// <param name="getValue">获取值的委托</param>
 public DictionaryEx(Converter <TKey, TValue> getValue)
 {
     Assertor.AreNull(getValue, "getValue");
     _items    = new Dictionary <TKey, TValue>();
     _getValue = getValue;
     _mode     = 2;
 }
Пример #4
0
 /// <summary> 初始化操作
 /// </summary>
 private void Initialize()
 {
     Assertor.AreNullOrWhiteSpace(ConnectionString, "ConnectionString");
     Assertor.AreNullOrWhiteSpace(ProviderName, "ProviderName");
     ConnectorKey   = string.Concat(ProviderName, "\f", ConnectionString);
     _isInitialized = true;
 }
Пример #5
0
 /// <summary> 初始化 DictionaryEx 设定getValue委托,key不存在时执行委托,并加入集合
 /// </summary>
 /// <param name="getValue">获取值的委托</param>
 /// <param name="isReadOnly">集合是否限制外部修改</param>
 public DictionaryEx(Converter <TKey, TValue> getValue, bool isReadOnly)
 {
     Assertor.AreNull(getValue, "getValue");
     _items     = new Dictionary <TKey, TValue>();
     _getValue  = getValue;
     IsReadOnly = isReadOnly;
     _mode      = 2;
 }
Пример #6
0
 /// <summary> 初始化 DictionaryEx, key不存在时返回defaultValue
 /// </summary>
 /// <param name="dictionary">内部字典</param>
 /// <param name="isReadOnly">是否只读</param>
 /// <param name="defaultValue">默认值</param>
 public DictionaryEx(IDictionary <TKey, TValue> dictionary, bool isReadOnly, TValue defaultValue = default(TValue))
 {
     Assertor.AreNull(dictionary, "dictionary");
     _items        = dictionary;
     IsReadOnly    = isReadOnly;
     _defaultValue = defaultValue;
     _mode         = 1;
 }
Пример #7
0
 /// <summary> 初始化 DictionaryEx 设定getValue委托,key不存在时执行委托,并加入集合
 /// </summary>
 /// <param name="getValue">获取值的委托</param>
 /// <param name="dictionary">内部字典</param>
 public DictionaryEx(Converter <TKey, TValue> getValue, IDictionary <TKey, TValue> dictionary)
 {
     Assertor.AreNull(getValue, "getValue");
     Assertor.AreNull(dictionary, "dictionary");
     _items     = dictionary;
     _getValue  = getValue;
     IsReadOnly = true;
     _mode      = 2;
 }
Пример #8
0
        /// <summary> 创建并返回 IDBHelper
        /// </summary>
        /// <param name="connectionString">数据连接字符串</param>
        /// <param name="providerName">提供程序的名称</param>
        public static IDBHelper Create(string connectionString, string providerName)
        {
            Assertor.AreNullOrWhiteSpace(connectionString, "connectionString");
            Assertor.AreNullOrWhiteSpace(providerName, "providerName");
            var helper = CreateDBHelper(providerName);

            helper.ConnectionString = connectionString;
            helper.ProviderName     = providerName;
            return(helper);
        }
Пример #9
0
 public SqlBuilder(DbTour tour, string sql, object[] args)
     : base(GetDbHelper(tour))
 {
     Assertor.AreNull(sql, "sql");
     if (args == null && sql.Length < 24 && sql.IndexOfAny(new char[] { ' ', '\r', '\n', '\t' }) == -1)
     {
         sql = "SELECT * FROM " + sql;
     }
     _fql   = tour._FQLProvider;
     _where = FQL.Format(_fql, sql, args).AsBuilder("WHERE");
 }
Пример #10
0
 public T ExecuteReader <T>(Converter <IDataReader, T> func)
 {
     Assertor.AreNull(func, "func");
     try
     {
         _parameters = Parameters;
         using (var reader = _helper.ExecuteReader(_commandType, CommandText, _parameters))
         {
             return(func(reader));
         }
     }
     finally
     {
         OnExecuted();
     }
 }
Пример #11
0
 public void ExecuteReader(Action <IDataReader> action)
 {
     Assertor.AreNull(action, "action");
     try
     {
         _parameters = Parameters;
         using (var reader = _helper.ExecuteReader(_commandType, CommandText, _parameters))
         {
             action(reader);
         }
     }
     finally
     {
         OnExecuted();
     }
 }
Пример #12
0
        /// <summary> 创建并返回 IDBHelper
        /// </summary>
        /// <param name="connectionName">配置节点的名称</param>
        public static IDBHelper Create(string connectionName)
        {
            Assertor.AreNullOrWhiteSpace(connectionName, "connectionName");
            var config = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName];

            if (config == null)
            {
                throw new KeyNotFoundException("不存在名为 " + connectionName + " 的节点");
            }
            var helper = CreateDBHelper(config.ProviderName);

            helper.ConnectionString = config.ConnectionString;
            helper.ProviderName     = config.ProviderName;
            helper.Name             = config.Name;
            return(helper);
        }
Пример #13
0
 public TValue this[TKey key]
 {
     get
     {
         TValue value;
         if (_items.TryGetValue(key, out value))
         {
             return(value);
         }
         return(ReturnValue(key));
     }
     set
     {
         Assertor.AreTrue(IsReadOnly, "集合为只读");
         _items[key] = value;
     }
 }
Пример #14
0
        private void Initialize()
        {
            Assertor.AreNull(_DBHelper, "DBHelper");
            var factory = _DBHelper as IDbComponentFactory;

            if (factory == null)
            {
                if (_DBHelper is SqlServerHelper)
                {
                    _FQLProvider = SqlServerFQL.Instance;
                    _Saw         = null;
                    return;
                }
                throw new NotSupportedException(TypesHelper.DisplayName(_DBHelper.GetType()) + " 没有实现 IDbComponentFactory 接口");
            }
            _FQLProvider = factory.CreateFQLProvider();
            _Saw         = factory.CreateSaw();
        }
Пример #15
0
        public VarObejct GetOutValue(string name)
        {
            Assertor.AreNullOrWhiteSpace(name, "name");
            if (_parameters == null)
            {
                throw new InvalidOperationException("尚未执行查询,无法获得返回值");
            }

            var length = _parameters.Length;

            for (int i = 0; i < length; i++)
            {
                if (_parameters[i].ParameterName == name)
                {
                    return(new VarObejct(_parameters[i].Value));
                }
            }
            throw new KeyNotFoundException("没有找到该名称的参数");
        }
Пример #16
0
 public T FirstOrDefault <T>(Converter <RowRecord, T> convert, T defaultValue = default(T))
 {
     Assertor.AreNull(convert, "convert");
     try
     {
         _parameters = Parameters;
         using (var reader = _helper.ExecuteReader(_commandType, CommandText, _parameters))
         {
             if (reader.Read())
             {
                 return(convert(new RowRecord(reader, false)));
             }
             return(defaultValue);
         }
     }
     finally
     {
         OnExecuted();
     }
 }
Пример #17
0
 public List <T> ToList <T>(Converter <RowRecord, T> convert)
 {
     Assertor.AreNull(convert, "convert");
     try
     {
         _parameters = Parameters;
         using (var reader = _helper.ExecuteReader(_commandType, CommandText, _parameters))
         {
             var row  = new RowRecord(reader, true);
             var list = new List <T>();
             while (reader.Read())
             {
                 list.Add(convert(row));
             }
             return(list);
         }
     }
     finally
     {
         OnExecuted();
     }
 }
Пример #18
0
 /// <summary> 构造 SimpleCounter 对象的实例。
 /// </summary>
 /// <param name="connector"></param>
 public SimpleCounter(IConnector connector)
 {
     Assertor.AreNull(connector, "connection");
     Connector = connector;
 }
Пример #19
0
 public bool Remove(TKey key)
 {
     Assertor.AreTrue(IsReadOnly, "集合为只读");
     return(_items.Remove(key));
 }
Пример #20
0
 private static IDBHelper GetDbHelper(DbTour tour)
 {
     Assertor.AreNull(tour, "tour");
     return(tour._DBHelper);
 }
Пример #21
0
 public void Clear()
 {
     Assertor.AreTrue(IsReadOnly, "集合为只读");
     _items.Clear();
 }