Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Attributes / PropertyAccess.cs
blob76654669dca4f2252238e32ebe95071d77a27be9
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord
17 using System;
19 /// <summary>
20 /// Define the various access strategies NHibernate will use to set/get the value
21 /// for this property.
22 /// </summary>
23 public enum PropertyAccess
25 /// <summary>
26 /// Use the property get/set methods to get and set the value of this property
27 /// </summary>
28 /// <example>
29 /// <code>
30 /// [Property(Access=PropertyAccess.Property)]
31 /// public string UserName { get {... } set { ... } }
32 /// </code>
33 /// </example>
34 Property,
35 /// <summary>
36 /// Use the field to get/set the value. (Only valid when specify on a field).
37 /// </summary>
38 /// <example>
39 /// <code>
40 /// [Property(Access=PropertyAccess.Field)]
41 /// public string UserName; // notice this is a field, not property.
42 /// </code>
43 /// </example>
44 Field,
45 /// <summary>
46 /// Use the field that is the backing store for this property to get/set the value of this property.
47 /// The field is using the same name as the property, in camel case.
48 /// </summary>
49 /// <example>
50 /// <code>
51 /// string userName;//this will be use to get or set the value
52 ///
53 /// [Property(Access=PropertyAccess.FieldCamelCase)]
54 /// public string UserName { get {... } set { ... } }
55 /// </code>
56 /// </example>
57 FieldCamelcase,
58 /// <summary>
59 /// Use the field that is the backing store for this property to get/set the value of this property.
60 /// The field is using the same name as the property, in camel case and with an initial underscore
61 /// </summary>
62 /// <example>
63 /// <code>
64 /// string _userName;//this will be use to get or set the value
65 ///
66 /// [Property(Access=PropertyAccess.FieldCamelcaseUnderscore)]
67 /// public string UserName { get {... } set { ... } }
68 /// </code>
69 /// </example>
70 FieldCamelcaseUnderscore,
71 /// <summary>
72 /// Use the field that is the backing store for this property to get/set the value of this property.
73 /// The field is using the same name as the property, in pascal case and with an initial m and then underscore.
74 /// m_Name for the property Name.
75 /// </summary>
76 /// <example>
77 /// <code>
78 /// string m_UserName;//this will be use to get or set the value
79 ///
80 /// [Property(Access=PropertyAccess.FieldPascalcaseMUnderscore)]
81 /// public string UserName { get {... } set { ... } }
82 /// </code>
83 /// </example>
84 FieldPascalcaseMUnderscore,
85 /// <summary>
86 /// Use the field that is the backing store for this property to get/set the value of this property.
87 /// The field is using the same name as the property, in all lower case and with inital underscore
88 /// </summary>
89 /// <example>
90 /// <code>
91 /// string _username;//this will be use to get or set the value
92 ///
93 /// [Property(Access=PropertyAccess.FieldLowercaseUnderscore)]
94 /// public string UserName { get {... } set { ... } }
95 /// </code>
96 /// </example>
97 FieldLowercaseUnderscore,
98 /// <summary>
99 /// Use the property' getter to get the value, and use the field with the same name and in camel case
100 /// in order to set it.
101 /// </summary>
102 /// <example>
103 /// <code>
104 /// string _userName;//this will be use to set the value
105 ///
106 /// [Property(Access=PropertyAccess.NosetterCamelcase)]
107 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
108 /// </code>
109 /// </example>
110 NosetterCamelcase,
111 /// <summary>
112 /// Use the property' getter to get the value, and use the field with the same name and in camel case
113 /// with initial "_" in order to set it.
114 /// </summary>
115 /// <example>
116 /// <code>
117 /// string _userName;//this will be use to set the value
118 ///
119 /// [Property(Access=PropertyAccess.NosetterCamelcaseUnderscore)]
120 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
121 /// </code>
122 /// </example>
123 NosetterCamelcaseUnderscore,
124 /// <summary>
125 /// Use the property' getter to get the value, and use the field with the same name and in pascal case
126 /// with initial "_" in order to set it.
127 /// </summary>
128 /// <example>
129 /// <code>
130 /// string _UserName;//this will be use to set the value
131 ///
132 /// [Property(Access=PropertyAccess.NosetterPascalcaseUnderscore)]
133 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
134 /// </code>
135 /// </example>
136 NosetterPascalcaseUnderscore,
137 /// <summary>
138 /// Use the property' getter to get the value, and use the field with the same name and in pascal case
139 /// with initial "m_" in order to set it.
140 /// </summary>
141 /// <example>
142 /// <code>
143 /// string m_UserName;//this will be use to set the value
144 ///
145 /// [Property(Access=PropertyAccess.NosetterPascalcaseMUndersc)]
146 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
147 /// </code>
148 /// </example>
149 NosetterPascalcaseMUndersc,
150 /// <summary>
151 /// Use the property' getter to get the value, and use the field with the same name and in lower case
152 /// with initial "_" in order to set it.
153 /// </summary>
154 /// <example>
155 /// <code>
156 /// string _username;//this will be use to set the value
157 ///
158 /// [Property(Access=PropertyAccess.NosetterLowercaseUnderscore)]
159 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
160 /// </code>
161 /// </example>
162 NosetterLowercaseUnderscore,
163 /// <summary>
164 /// Use the property' getter to get the value, and use the field with the same name and in lower case
165 /// in order to set it.
166 /// </summary>
167 /// <example>
168 /// <code>
169 /// string username;//this will be use to set the value
170 ///
171 /// [Property(Access=PropertyAccess.NosetterLowercase)]
172 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
173 /// </code>
174 /// </example>
175 NosetterLowercase
178 /// <summary>
179 /// Utility class to help convert between <see cref="PropertyAccess"/> values and
180 /// NHiberante's access strategies.
181 /// </summary>
182 public class PropertyAccessHelper
184 /// <summary>
185 /// Convert <param name="access"/> to its NHibernate string
186 /// </summary>
187 public static string ToString(PropertyAccess access)
189 switch (access)
191 case PropertyAccess.Property:
192 return "property";
193 case PropertyAccess.Field:
194 return "field";
195 case PropertyAccess.FieldCamelcase:
196 return "field.camelcase";
197 case PropertyAccess.FieldCamelcaseUnderscore:
198 return "field.camelcase-underscore";
199 case PropertyAccess.FieldPascalcaseMUnderscore:
200 return "field.pascalcase-m-underscore";
201 case PropertyAccess.FieldLowercaseUnderscore:
202 return "field.lowercase-underscore";
203 case PropertyAccess.NosetterCamelcase:
204 return "nosetter.camelcase";
205 case PropertyAccess.NosetterCamelcaseUnderscore:
206 return "nosetter.camelcase-underscore";
207 case PropertyAccess.NosetterPascalcaseMUndersc:
208 return "nosetter.pascalcase-m-underscore";
209 case PropertyAccess.NosetterPascalcaseUnderscore:
210 return "nosetter.pascalcase-underscore";
211 case PropertyAccess.NosetterLowercaseUnderscore:
212 return "nosetter.lowercase-underscore";
213 case PropertyAccess.NosetterLowercase:
214 return "nosetter.lowercase";
215 default:
216 throw new InvalidOperationException("Invalid value for PropertyAccess");