2010-07-23 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ProfileParameter.cs
1 //
2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
3 //
4 // Authors:
5 //      Vladimir Krasnov <vladimirk@mainsoft.com>
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
27 #if NET_2_0
28
29 using System;
30 using System.Collections.Generic;
31 using System.ComponentModel;
32 using System.Data;
33 using System.Text;
34
35 namespace System.Web.UI.WebControls
36 {
37         [DefaultProperty ("PropertyName")]
38         public class ProfileParameter : Parameter
39         {
40                 public ProfileParameter ()
41                         : base ()
42                 {
43                 }
44
45                 protected ProfileParameter (ProfileParameter original)
46                         : base (original)
47                 {
48                         this.PropertyName = original.PropertyName;
49                 }
50
51                 public ProfileParameter (string name, string propertyName)
52                         : base (name)
53                 {
54                         this.PropertyName = propertyName;
55                 }
56
57                 public ProfileParameter (string name, TypeCode type, string propertyName)
58                         : base (name, type)
59                 {
60                         this.PropertyName = propertyName;
61                 }
62
63                 public ProfileParameter (string name, DbType dbType, string propertyName)
64                         : base (name, dbType)
65                 {
66                         this.PropertyName = propertyName;
67                 }
68                 
69                 protected override Parameter Clone ()
70                 {
71                         return new ProfileParameter (this);
72                 }
73 #if NET_4_0
74                 protected internal
75 #else
76                 protected
77 #endif
78                 override object Evaluate (HttpContext context, Control control)
79                 {
80                         if (context == null || context.Profile == null)
81                                 return null;
82
83                         if (string.IsNullOrEmpty (PropertyName))
84                                 return null;
85
86                         return context.Profile [PropertyName];
87                 }
88
89                 [DefaultValue ("")]
90                 public string PropertyName {
91                         get {
92                                 object o = ViewState ["PropertyName"];
93                                 return (o != null) ? (string) o : string.Empty;
94                         }
95                         set { ViewState ["PropertyName"] = value; }
96                 }
97
98         }
99 }
100
101 #endif