From: Michael D. <mik...@us...> - 2004-08-23 13:11:21
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Property In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15811/NHibernate/Property Modified Files: BasicPropertyAccessor.cs FieldAccessor.cs PascalCaseMUnderscoreStrategy.cs PropertyAccessorFactory.cs Log Message: Added comments to GetPropertyAccessor and changed access modifiers of some helper functions. Index: BasicPropertyAccessor.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Property/BasicPropertyAccessor.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BasicPropertyAccessor.cs 22 Aug 2004 06:18:54 -0000 1.1 --- BasicPropertyAccessor.cs 23 Aug 2004 13:11:08 -0000 1.2 *************** *** 30,34 **** #endregion ! private static BasicSetter GetSetterOrNull(System.Type type, string propertyName) { if (type == typeof(object) || type == null) return null; --- 30,34 ---- #endregion ! internal static BasicSetter GetSetterOrNull(System.Type type, string propertyName) { if (type == typeof(object) || type == null) return null; *************** *** 56,60 **** } ! private static BasicGetter GetGetterOrNull(System.Type type, string propertyName) { if (type==typeof(object) || type==null) return null; --- 56,60 ---- } ! internal static BasicGetter GetGetterOrNull(System.Type type, string propertyName) { if (type==typeof(object) || type==null) return null; Index: PropertyAccessorFactory.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Property/PropertyAccessorFactory.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PropertyAccessorFactory.cs 23 Aug 2004 02:10:06 -0000 1.2 --- PropertyAccessorFactory.cs 23 Aug 2004 13:11:08 -0000 1.3 *************** *** 16,20 **** private static readonly IPropertyAccessor fieldCamelCaseUnderscoreAccessor = new FieldAccessor( new CamelCaseUnderscoreStrategy() ); private static readonly IPropertyAccessor fieldPascalCaseMUnderscoreAccessor = new FieldAccessor( new PascalCaseMUnderscoreStrategy() ); ! private PropertyAccessorFactory() --- 16,22 ---- private static readonly IPropertyAccessor fieldCamelCaseUnderscoreAccessor = new FieldAccessor( new CamelCaseUnderscoreStrategy() ); private static readonly IPropertyAccessor fieldPascalCaseMUnderscoreAccessor = new FieldAccessor( new PascalCaseMUnderscoreStrategy() ); ! private static readonly IPropertyAccessor noSetterCamelCaseAccessor = new NoSetterAccessor( new CamelCaseStrategy() ); ! private static readonly IPropertyAccessor noSetterCamelCaseUnderscoreAccessor = new NoSetterAccessor( new CamelCaseUnderscoreStrategy() ); ! private static readonly IPropertyAccessor noSetterPascalCaseMUnderscoreAccessor = new NoSetterAccessor( new PascalCaseMUnderscoreStrategy() ); private PropertyAccessorFactory() *************** *** 23,26 **** --- 25,116 ---- } + /// <summary> + /// Gets or creates the IPropertyAccessor specified by the type. + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + /// <remarks> + /// <p> + /// The built in ways of accessing the values of Properties in your domain class are: + /// </p> + /// <list type="table"> + /// <listheader> + /// <term>access method</term> + /// <description>How NHibernate accesses the Mapped Class.</description> + /// </listheader> + /// <item> + /// <term>property</term> + /// <description> + /// The <c>name</c> attribute is the name of the Property. This is the + /// default implementation. + /// </description> + /// </item> + /// <item> + /// <term>field</term> + /// <description> + /// The <c>name</c> attribute is the name of the field. If you have any Properties + /// in the Mapped Class those will be bypassed and NHibernate will go straight to the + /// field. This is a good option if your setters have business rules attached to them + /// or if you don't want to expose a field through a Getter & Setter. + /// </description> + /// </item> + /// <item> + /// <term>nosetter</term> + /// <description> + /// The <c>name</c> attribute is the name of the Property. NHibernate will use the + /// Property's get method to retreive the value and will use the field + /// to set the value. This is a good option for <id> Properties because this access method + /// allow's users of the Class to get the value of the Id but not set the value. + /// </description> + /// </item> + /// <item> + /// <term>Assembly Qualified Name</term> + /// <description> + /// If NHibernate's built in <see cref="IPropertyAccessor"/>s are not what is needed for your + /// situation then you are free to build your own. Provide an Assembly Qualified Name so that + /// NHibernate can call <c>Activator.CreateInstance(AssemblyQualifiedName)</c> to create it. + /// </description> + /// </item> + /// </list> + /// <p> + /// In order for the <c>nosetter</c> to know the name of the field to access NHibernate needs to know + /// what the naming strategy is. The following naming strategies are built into NHibernate: + /// </p> + /// <list type="table"> + /// <item> + /// <term>camelcase</term> + /// <description> + /// The <c>name</c> attribute should be changed to CamelCase to find the field. + /// <c><property name="Foo" ... ></c> finds a field <c>foo</c>. + /// </description> + /// </item> + /// <item> + /// <term>camelcase-underscore</term> + /// <description> + /// The <c>name</c> attribute should be changed to CamelCase and prefixed with + /// an underscore to find the field. + /// <c><property name="Foo" ... ></c> finds a field <c>_foo</c>. + /// </description> + /// </item> + /// <item> + /// <term>pascalcase-m-underscore</term> + /// <description> + /// The <c>name</c> attribute should be changed to CamelCase to find the field. + /// <c><property name="Foo" ... ></c> finds a field <c>m_Foo</c>. + /// </description> + /// </item> + /// </list> + /// <para> + /// The naming strategy can also be appended at the end of the <c>field</c> access method. Where + /// this could be useful is a scenario where you do expose a get and set method in the Domain Class + /// but NHibernate should only use the fields. + /// </para> + /// <para> + /// With a naming strategy and a get/set for the Property available the user of the Domain Class + /// could write an Hql statement <c>from Foo as foo where foo.SomeProperty = 'a'</c>. If no naming + /// strategy was specified the Hql statement whould have to be <c>from Foo as foo where foo._someProperty</c> + /// (assuming CamelCase with an underscore field naming strategy is used). + /// </para> + /// </remarks> public static IPropertyAccessor GetPropertyAccessor(string type) { *************** *** 31,40 **** --- 121,143 ---- case "field" : return fieldAccessor; + case "field.camelcase" : return fieldCamelCaseAccessor; + case "field.camelcase-underscore" : return fieldCamelCaseUnderscoreAccessor; + case "field.pascalcase-m-underscore" : return fieldPascalCaseMUnderscoreAccessor; + + case "nosetter.camelcase" : + return noSetterCamelCaseAccessor; + + case "nosetter.camelcase-underscore" : + return noSetterCamelCaseUnderscoreAccessor; + + case "nosetter.pascalcase-m-underscore" : + return noSetterPascalCaseMUnderscoreAccessor; + } Index: PascalCaseMUnderscoreStrategy.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Property/PascalCaseMUnderscoreStrategy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PascalCaseMUnderscoreStrategy.cs 23 Aug 2004 02:10:06 -0000 1.1 --- PascalCaseMUnderscoreStrategy.cs 23 Aug 2004 13:11:08 -0000 1.2 *************** *** 5,9 **** /// <summary> /// Implementation of FieldNamingStrategy for fields that are prefixed with ! /// an "m_" and the PropertyName. /// </summary> public class PascalCaseMUnderscoreStrategy : IFieldNamingStrategy --- 5,9 ---- /// <summary> /// Implementation of FieldNamingStrategy for fields that are prefixed with ! /// an "m_" and the first character in PropertyName capitalized. /// </summary> public class PascalCaseMUnderscoreStrategy : IFieldNamingStrategy *************** *** 14,18 **** public string GetFieldName(string propertyName) { ! return "m_" + propertyName; } --- 14,18 ---- public string GetFieldName(string propertyName) { ! return "m_" + propertyName.Substring(0, 1).ToUpper() + propertyName.Substring(1); } Index: FieldAccessor.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Property/FieldAccessor.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FieldAccessor.cs 23 Aug 2004 02:10:06 -0000 1.2 --- FieldAccessor.cs 23 Aug 2004 13:11:08 -0000 1.3 *************** *** 8,14 **** /// </summary> /// <remarks> ! /// This accesses fields with the following naming convention: /// Property Name = "Id" ! /// Field Name = "id" /// </remarks> public class FieldAccessor : IPropertyAccessor --- 8,15 ---- /// </summary> /// <remarks> ! /// This accesses fields with the following naming convention unless a ! /// <see cref="IFieldNamingStrategy"/> is supplied. /// Property Name = "Id" ! /// Field Name = "Id" /// </remarks> public class FieldAccessor : IPropertyAccessor *************** *** 41,45 **** #endregion ! private static FieldInfo GetField(System.Type clazz, string fieldName) { if( clazz==null || clazz==typeof(object) ) --- 42,46 ---- #endregion ! internal static FieldInfo GetField(System.Type clazz, string fieldName) { if( clazz==null || clazz==typeof(object) ) |