Gets or creates the IPropertyAccessor specified by the type.

Namespace: NHibernate.Properties
Assembly: NHibernate (in NHibernate.dll) Version: 3.2.0.4000 (3.2.0.4000)

Syntax

C#
public static IPropertyAccessor GetPropertyAccessor(
	string type
)
Visual Basic
Public Shared Function GetPropertyAccessor ( _
	type As String _
) As IPropertyAccessor
Visual C++
public:
static IPropertyAccessor^ GetPropertyAccessor(
	String^ type
)

Parameters

type
Type: System..::..String

[Missing <param name="type"/> documentation for "M:NHibernate.Properties.PropertyAccessorFactory.GetPropertyAccessor(System.String)"]

Return Value

The IPropertyAccessor specified by the type.

Remarks

The built in ways of accessing the values of Properties in your domain class are:

Access MethodHow NHibernate accesses the Mapped Class.
property The name attribute is the name of the Property. This is the default implementation.
field The name 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.
nosetter The name attribute is the name of the Property. NHibernate will use the Property's get method to retrieve the value and will use the field to set the value. This is a good option for <id> Properties because this access method allows users of the Class to get the value of the Id but not set the value.
readonly The name attribute is the name of the Property. NHibernate will use the Property's get method to retrieve the value but will never set the value back in the domain. This is used for read-only calculated properties with only a get method.
Assembly Qualified Name If NHibernate's built in IPropertyAccessors 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 Activator.CreateInstance(AssemblyQualifiedName) to create it.

In order for the nosetter 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:

Naming StrategyHow NHibernate converts the value of the name attribute to a field name.
camelcase The name attribute should be changed to CamelCase to find the field. <property name="FooBar" ... > finds a field fooBar.
camelcase-underscore The name attribute should be changed to CamelCase and prefixed with an underscore to find the field. <property name="FooBar" ... > finds a field _fooBar.
camelcase-m-underscore The name attribute should be changed to CamelCase and prefixed with an 'm' and underscore to find the field. <property name="FooBar" ... > finds a field m_fooBar.
pascalcase-underscore The name attribute should be prefixed with an underscore to find the field. <property name="FooBar" ... > finds a field _FooBar.
pascalcase-m-underscore The name attribute should be prefixed with an 'm' and underscore to find the field. <property name="FooBar" ... > finds a field m_FooBar.
pascalcase-m The name attribute should be prefixed with an 'm'. <property name="FooBar" ... > finds a field mFooBar.
lowercase The name attribute should be changed to lowercase to find the field. <property name="FooBar" ... > finds a field foobar.
lowercase-underscore The name attribute should be changed to lowercase and prefixed with and underscore to find the field. <property name="FooBar" ... > finds a field _foobar.

The naming strategy can also be appended at the end of the field 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.

With a naming strategy and a get/set for the Property available the user of the Domain Class could write an Hql statement from Foo as foo where foo.SomeProperty = 'a'. If no naming strategy was specified the Hql statement would have to be from Foo as foo where foo._someProperty (assuming CamelCase with an underscore field naming strategy is used).

See Also