From: Sergey K. <jus...@us...> - 2005-04-24 19:38:05
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31965/src/NHibernate/Util Modified Files: ReflectHelper.cs Log Message: Integrated two more tests from H2.1, fixed uncovered bugs. Index: ReflectHelper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Util/ReflectHelper.cs,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ReflectHelper.cs 5 Apr 2005 14:21:21 -0000 1.26 --- ReflectHelper.cs 24 Apr 2005 19:37:57 -0000 1.27 *************** *** 281,284 **** --- 281,318 ---- } + public static ConstructorInfo GetConstructor(System.Type type, IType[] types) + { + ConstructorInfo[] candidates = type.GetConstructors( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); + + foreach( ConstructorInfo constructor in candidates ) + { + ParameterInfo[] parameters = constructor.GetParameters(); + + if( parameters.Length == types.Length ) + { + bool found = true; + + for( int j = 0; j < parameters.Length; j++ ) + { + bool ok = parameters[j].ParameterType.IsAssignableFrom( + types[j].ReturnedClass ); + + if( !ok ) + { + found = false; + break; + } + } + + if (found) + { + return constructor; + } + } + } + throw new InstantiationException( "no appropriate constructor in class: " + + type.FullName ); + } + /// <summary> /// Determines if the <see cref="System.Type"/> is a non creatable class. |