Beispiel #1
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;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /// <summary> 初始化 DictionaryEx 只读集合
 /// </summary>
 /// <param name="dictionary">内部字典</param>
 public DictionaryEx(IDictionary <TKey, TValue> dictionary)
 {
     Assertor.AreNull(dictionary, "dictionary");
     IsReadOnly = true;
     _items     = dictionary;
     _mode      = 0;
 }
Beispiel #4
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;
 }
Beispiel #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;
 }
Beispiel #6
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;
 }
Beispiel #7
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");
 }
Beispiel #8
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();
     }
 }
Beispiel #9
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();
     }
 }
Beispiel #10
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();
        }
Beispiel #11
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();
     }
 }
Beispiel #12
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();
     }
 }
Beispiel #13
0
 /// <summary> 构造 SimpleCounter 对象的实例。
 /// </summary>
 /// <param name="connector"></param>
 public SimpleCounter(IConnector connector)
 {
     Assertor.AreNull(connector, "connection");
     Connector = connector;
 }
Beispiel #14
0
 private static IDBHelper GetDbHelper(DbTour tour)
 {
     Assertor.AreNull(tour, "tour");
     return(tour._DBHelper);
 }