EasyDbParameterCollection.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.Common;
  5. using System.Linq;
  6. namespace EasyDevCore.Database
  7. {
  8. /// <summary>
  9. ///
  10. /// </summary>
  11. [Serializable]
  12. public sealed class EasyDbParameterCollection : IEnumerable<EasyDbParameter>
  13. {
  14. private Dictionary<string, EasyDbParameter> m_List;
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="EasyDbParameterCollection" /> class.
  17. /// </summary>
  18. public EasyDbParameterCollection()
  19. {
  20. m_List = new Dictionary<string, EasyDbParameter>();
  21. }
  22. /// <summary>
  23. /// Adds the specified p.
  24. /// </summary>
  25. /// <param name="parameter">The parameter.</param>
  26. /// <returns></returns>
  27. /// <column name="p">The p.</column>
  28. public EasyDbParameter Add(EasyDbParameter parameter)
  29. {
  30. m_List.Add(parameter.ParameterName, parameter);
  31. return parameter;
  32. }
  33. /// <summary>
  34. /// Removes the specified parameter name.
  35. /// </summary>
  36. /// <param name="parameterName">Name of the parameter.</param>
  37. /// <returns></returns>
  38. public bool Remove(string parameterName)
  39. {
  40. return m_List.Remove(parameterName);
  41. }
  42. /// <summary>
  43. /// Gets the count.
  44. /// </summary>
  45. /// <column>The count.</column>
  46. public int Count
  47. {
  48. get
  49. {
  50. return m_List.Count;
  51. }
  52. }
  53. /// <summary>
  54. /// Determines whether [contains] [the specified name].
  55. /// </summary>
  56. /// <param name="name">The name.</param>
  57. /// <returns>
  58. /// <c>true</c> if [contains] [the specified name]; otherwise, <c>false</c>.
  59. /// </returns>
  60. public bool Contains(string name)
  61. {
  62. return m_List.ContainsKey(name);
  63. }
  64. /// <summary>
  65. /// Gets the <see cref="EasyDbParameter" /> with the specified name.
  66. /// </summary>
  67. /// <value>
  68. /// The <see cref="EasyDbParameter" />.
  69. /// </value>
  70. /// <param name="name">The name.</param>
  71. /// <returns></returns>
  72. public EasyDbParameter this[string name]
  73. {
  74. get
  75. {
  76. return Contains(name) ? m_List[name] : null;
  77. }
  78. }
  79. /// <summary>
  80. /// Gets the <see cref="EasyDbParameter" /> at the specified index.
  81. /// </summary>
  82. /// <value>
  83. /// The <see cref="EasyDbParameter" />.
  84. /// </value>
  85. /// <param name="index">The index.</param>
  86. /// <returns></returns>
  87. public EasyDbParameter this[int index]
  88. {
  89. get
  90. {
  91. return m_List.Values.ElementAtOrDefault(index);
  92. }
  93. }
  94. #region IEnumerable<DbDataParameter> Members
  95. /// <summary>
  96. /// Returns an enumerator that iterates through the collection.
  97. /// </summary>
  98. /// <returns>
  99. /// A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection.
  100. /// </returns>
  101. IEnumerator<EasyDbParameter> IEnumerable<EasyDbParameter>.GetEnumerator()
  102. {
  103. return m_List.Values.GetEnumerator();
  104. }
  105. #endregion
  106. #region IEnumerable Members
  107. /// <summary>
  108. /// Returns an enumerator that iterates through a collection.
  109. /// </summary>
  110. /// <returns>
  111. /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
  112. /// </returns>
  113. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  114. {
  115. IEnumerable<EasyDbParameter> enumerable = this;
  116. return enumerable.GetEnumerator();
  117. }
  118. #endregion
  119. }
  120. }