CommandParameterCollection.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections;
  5. using FastReport.Utils;
  6. namespace FastReport.Data
  7. {
  8. /// <summary>
  9. /// Represents the collection of <see cref="CommandParameter"/> objects.
  10. /// </summary>
  11. /// <remarks>
  12. /// This class is used to store the list of parameters defined in the datasource. See the
  13. /// <see cref="TableDataSource.Parameters"/> property for more details.
  14. /// </remarks>
  15. public class CommandParameterCollection : FRCollectionBase
  16. {
  17. /// <summary>
  18. /// Gets or sets a parameter.
  19. /// </summary>
  20. /// <param name="index">The index of a parameter in this collection.</param>
  21. /// <returns>The parameter with specified index.</returns>
  22. public CommandParameter this[int index]
  23. {
  24. get { return List[index] as CommandParameter; }
  25. set { List[index] = value; }
  26. }
  27. /// <summary>
  28. /// Finds a parameter by its name.
  29. /// </summary>
  30. /// <param name="name">The name of a parameter.</param>
  31. /// <returns>The <see cref="CommandParameter"/> object if found; otherwise <b>null</b>.</returns>
  32. public CommandParameter FindByName(string name)
  33. {
  34. foreach (CommandParameter c in this)
  35. {
  36. if (c.Name == name)
  37. return c;
  38. }
  39. return null;
  40. }
  41. /// <summary>
  42. /// Returns an unique parameter name based on given name.
  43. /// </summary>
  44. /// <param name="name">The base name.</param>
  45. /// <returns>The unique name.</returns>
  46. public string CreateUniqueName(string name)
  47. {
  48. string baseName = name;
  49. int i = 1;
  50. while (FindByName(name) != null)
  51. {
  52. name = baseName + i.ToString();
  53. i++;
  54. }
  55. return name;
  56. }
  57. /// <summary>
  58. /// Initializes a new instance of the <see cref="CommandParameterCollection"/> class with default settings.
  59. /// </summary>
  60. /// <param name="owner">The owner of this collection.</param>
  61. public CommandParameterCollection(Base owner) : base(owner)
  62. {
  63. }
  64. }
  65. }