ProfileParameter.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  3. //
  4. // Authors:
  5. // Vladimir Krasnov <[email protected]>
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining
  8. // a copy of this software and associated documentation files (the
  9. // "Software"), to deal in the Software without restriction, including
  10. // without limitation the rights to use, copy, modify, merge, publish,
  11. // distribute, sublicense, and/or sell copies of the Software, and to
  12. // permit persons to whom the Software is furnished to do so, subject to
  13. // the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be
  16. // included in all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. //
  26. #if NET_2_0
  27. using System;
  28. using System.Collections.Generic;
  29. using System.ComponentModel;
  30. using System.Data;
  31. using System.Text;
  32. namespace System.Web.UI.WebControls
  33. {
  34. [DefaultProperty ("PropertyName")]
  35. public class ProfileParameter : Parameter
  36. {
  37. public ProfileParameter ()
  38. : base ()
  39. {
  40. }
  41. protected ProfileParameter (ProfileParameter original)
  42. : base (original)
  43. {
  44. this.PropertyName = original.PropertyName;
  45. }
  46. public ProfileParameter (string name, string propertyName)
  47. : base (name)
  48. {
  49. this.PropertyName = propertyName;
  50. }
  51. public ProfileParameter (string name, TypeCode type, string propertyName)
  52. : base (name, type)
  53. {
  54. this.PropertyName = propertyName;
  55. }
  56. public ProfileParameter (string name, DbType dbType, string propertyName)
  57. : base (name, dbType)
  58. {
  59. this.PropertyName = propertyName;
  60. }
  61. protected override Parameter Clone ()
  62. {
  63. return new ProfileParameter (this);
  64. }
  65. #if NET_4_0
  66. protected internal
  67. #else
  68. protected
  69. #endif
  70. override object Evaluate (HttpContext context, Control control)
  71. {
  72. if (context == null || context.Profile == null)
  73. return null;
  74. if (string.IsNullOrEmpty (PropertyName))
  75. return null;
  76. return context.Profile [PropertyName];
  77. }
  78. [DefaultValue ("")]
  79. public string PropertyName {
  80. get {
  81. object o = ViewState ["PropertyName"];
  82. return (o != null) ? (string) o : string.Empty;
  83. }
  84. set { ViewState ["PropertyName"] = value; }
  85. }
  86. }
  87. }
  88. #endif