1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
20 /// Define the various access strategies NHibernate will use to set/get the value
21 /// for this property.
23 public enum PropertyAccess
26 /// Use the property get/set methods to get and set the value of this property
30 /// [Property(Access=PropertyAccess.Property)]
31 /// public string UserName { get {... } set { ... } }
36 /// Use the field to get/set the value. (Only valid when specify on a field).
40 /// [Property(Access=PropertyAccess.Field)]
41 /// public string UserName; // notice this is a field, not property.
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.
51 /// string userName;//this will be use to get or set the value
53 /// [Property(Access=PropertyAccess.FieldCamelCase)]
54 /// public string UserName { get {... } set { ... } }
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
64 /// string _userName;//this will be use to get or set the value
66 /// [Property(Access=PropertyAccess.FieldCamelcaseUnderscore)]
67 /// public string UserName { get {... } set { ... } }
70 FieldCamelcaseUnderscore
,
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.
78 /// string m_UserName;//this will be use to get or set the value
80 /// [Property(Access=PropertyAccess.FieldPascalcaseMUnderscore)]
81 /// public string UserName { get {... } set { ... } }
84 FieldPascalcaseMUnderscore
,
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
91 /// string _username;//this will be use to get or set the value
93 /// [Property(Access=PropertyAccess.FieldLowercaseUnderscore)]
94 /// public string UserName { get {... } set { ... } }
97 FieldLowercaseUnderscore
,
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.
104 /// string _userName;//this will be use to set the value
106 /// [Property(Access=PropertyAccess.NosetterCamelcase)]
107 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
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.
117 /// string _userName;//this will be use to set the value
119 /// [Property(Access=PropertyAccess.NosetterCamelcaseUnderscore)]
120 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
123 NosetterCamelcaseUnderscore
,
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.
130 /// string _UserName;//this will be use to set the value
132 /// [Property(Access=PropertyAccess.NosetterPascalcaseUnderscore)]
133 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
136 NosetterPascalcaseUnderscore
,
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.
143 /// string m_UserName;//this will be use to set the value
145 /// [Property(Access=PropertyAccess.NosetterPascalcaseMUndersc)]
146 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
149 NosetterPascalcaseMUndersc
,
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.
156 /// string _username;//this will be use to set the value
158 /// [Property(Access=PropertyAccess.NosetterLowercaseUnderscore)]
159 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
162 NosetterLowercaseUnderscore
,
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.
169 /// string username;//this will be use to set the value
171 /// [Property(Access=PropertyAccess.NosetterLowercase)]
172 /// public string UserName { get {... } set { ... } } // this will be used just to get the value
179 /// Utility class to help convert between <see cref="PropertyAccess"/> values and
180 /// NHiberante's access strategies.
182 public class PropertyAccessHelper
185 /// Convert <param name="access"/> to its NHibernate string
187 public static string ToString(PropertyAccess access
)
191 case PropertyAccess
.Property
:
193 case PropertyAccess
.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";
216 throw new InvalidOperationException("Invalid value for PropertyAccess");