@@ -23,7 +23,7 @@ namespace NHibernate.Transform
2323 /// )
2424 /// .SetResultTransformer( new AliasToBeanResultTransformer(typeof(StudentDTO)))
2525 /// .List();
26- ///
26+ ///
2727 /// StudentDTO dto = (StudentDTO)resultWithAliasedBean[0];
2828 /// </code>
2929 /// </example>
@@ -35,23 +35,21 @@ namespace NHibernate.Transform
3535 [ Serializable ]
3636 public class AliasToBeanResultTransformer : AliasedTupleSubsetResultTransformer , IEquatable < AliasToBeanResultTransformer >
3737 {
38- private readonly System . Type _resultClass ;
39- private readonly ConstructorInfo _beanConstructor ;
4038 private readonly Dictionary < string , NamedMember < FieldInfo > > _fieldsByNameCaseSensitive ;
4139 private readonly Dictionary < string , NamedMember < FieldInfo > > _fieldsByNameCaseInsensitive ;
4240 private readonly Dictionary < string , NamedMember < PropertyInfo > > _propertiesByNameCaseSensitive ;
4341 private readonly Dictionary < string , NamedMember < PropertyInfo > > _propertiesByNameCaseInsensitive ;
4442
4543 public AliasToBeanResultTransformer ( System . Type resultClass )
4644 {
47- _resultClass = resultClass ?? throw new ArgumentNullException ( "resultClass" ) ;
45+ ResultClass = resultClass ?? throw new ArgumentNullException ( "resultClass" ) ;
4846
4947 const BindingFlags bindingFlags = BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ;
50- _beanConstructor = resultClass . GetConstructor ( bindingFlags , null , System . Type . EmptyTypes , null ) ;
48+ BeanConstructor = resultClass . GetConstructor ( bindingFlags , null , System . Type . EmptyTypes , null ) ;
5149
52- // if resultClass is a ValueType (struct), GetConstructor will return null...
50+ // if resultClass is a ValueType (struct), GetConstructor will return null...
5351 // in that case, we'll use Activator.CreateInstance instead of the ConstructorInfo to create instances
54- if ( _beanConstructor == null && resultClass . IsClass )
52+ if ( BeanConstructor == null && resultClass . IsClass )
5553 {
5654 throw new ArgumentException (
5755 "The target class of a AliasToBeanResultTransformer need a parameter-less constructor" ,
@@ -68,6 +66,9 @@ public AliasToBeanResultTransformer(System.Type resultClass)
6866 _propertiesByNameCaseInsensitive = GetMapByName ( properties , StringComparer . OrdinalIgnoreCase ) ;
6967 }
7068
69+ protected System . Type ResultClass { get ; }
70+ protected ConstructorInfo BeanConstructor { get ; }
71+
7172 public override bool IsTransformedValueATupleElement ( String [ ] aliases , int tupleLength )
7273 {
7374 return false ;
@@ -83,9 +84,9 @@ public override object TransformTuple(object[] tuple, String[] aliases)
8384
8485 try
8586 {
86- result = _resultClass . IsClass
87- ? _beanConstructor . Invoke ( null )
88- : Activator . CreateInstance ( _resultClass , true ) ;
87+ result = ResultClass . IsClass
88+ ? BeanConstructor . Invoke ( null )
89+ : Activator . CreateInstance ( ResultClass , true ) ;
8990
9091 for ( int i = 0 ; i < aliases . Length ; i ++ )
9192 {
@@ -94,11 +95,11 @@ public override object TransformTuple(object[] tuple, String[] aliases)
9495 }
9596 catch ( InstantiationException e )
9697 {
97- throw new HibernateException ( "Could not instantiate result class: " + _resultClass . FullName , e ) ;
98+ throw new HibernateException ( "Could not instantiate result class: " + ResultClass . FullName , e ) ;
9899 }
99100 catch ( MethodAccessException e )
100101 {
101- throw new HibernateException ( "Could not instantiate result class: " + _resultClass . FullName , e ) ;
102+ throw new HibernateException ( "Could not instantiate result class: " + ResultClass . FullName , e ) ;
102103 }
103104
104105 return result ;
@@ -111,7 +112,7 @@ public override IList TransformList(IList collection)
111112
112113 protected virtual void OnPropertyNotFound ( string propertyName )
113114 {
114- throw new PropertyNotFoundException ( _resultClass . GetType ( ) , propertyName , "setter" ) ;
115+ throw new PropertyNotFoundException ( ResultClass . GetType ( ) , propertyName , "setter" ) ;
115116 }
116117
117118 #region Setter resolution
@@ -126,7 +127,7 @@ protected virtual void OnPropertyNotFound(string propertyName)
126127 /// <exception cref="PropertyNotFoundException">Thrown if no matching property or field can be found.</exception>
127128 /// <exception cref="AmbiguousMatchException">Thrown if many matching properties or fields are found, having the
128129 /// same visibility and inheritance depth.</exception>
129- private void SetProperty ( string alias , object value , object resultObj )
130+ protected void SetProperty ( string alias , object value , object resultObj )
130131 {
131132 if ( alias == null )
132133 // Grouping properties in criteria are selected without alias, just ignore them.
@@ -187,7 +188,7 @@ private void CheckMember<T>(NamedMember<T> member, string alias) where T : Membe
187188 private void FetchFieldsAndProperties ( List < RankedMember < FieldInfo > > fields , List < RankedMember < PropertyInfo > > properties )
188189 {
189190 const BindingFlags bindingFlags = BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . DeclaredOnly ;
190- var currentType = _resultClass ;
191+ var currentType = ResultClass ;
191192 var rank = 1 ;
192193 // For grasping private members, we need to manually walk the hierarchy.
193194 while ( currentType != null && currentType != typeof ( object ) )
@@ -315,12 +316,12 @@ public bool Equals(AliasToBeanResultTransformer other)
315316 {
316317 return true ;
317318 }
318- return Equals ( other . _resultClass , _resultClass ) ;
319+ return Equals ( other . ResultClass , ResultClass ) ;
319320 }
320321
321322 public override int GetHashCode ( )
322323 {
323- return _resultClass . GetHashCode ( ) ;
324+ return ResultClass . GetHashCode ( ) ;
324325 }
325326
326327 #endregion
0 commit comments