Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv6556
Modified Files:
SimpleInstantiationStrategy.cs
Log Message:
Allow non public zero-arg construstors to be used by Spring.
Index: SimpleInstantiationStrategy.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support/SimpleInstantiationStrategy.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** SimpleInstantiationStrategy.cs 15 Oct 2007 23:32:39 -0000 1.17
--- SimpleInstantiationStrategy.cs 7 Apr 2008 00:30:34 -0000 1.18
***************
*** 87,101 ****
else
{
! if (definition.HasObjectType)
! {
! return ObjectUtils.InstantiateType(definition.ObjectType);
! }
! else
! {
! return ObjectUtils.InstantiateType(TypeResolutionUtils.ResolveType(definition.ObjectTypeName));
! }
}
}
/// <summary>
/// Instantiate an instance of the object described by the supplied
--- 87,120 ----
else
{
! Type objectType = definition.HasObjectType
! ? definition.ObjectType
! : TypeResolutionUtils.ResolveType(definition.ObjectTypeName);
! ConstructorInfo constructor = GetZeroArgConstructorInfo(objectType);
! return ObjectUtils.InstantiateType(constructor, ObjectUtils.EmptyObjects);
}
}
+ /// <summary>
+ /// Gets the zero arg ConstructorInfo object, if the type offers such functionality.
+ /// </summary>
+ /// <param name="type">The type.</param>
+ /// <returns>Zero argument ConstructorInfo</returns>
+ /// <exception cref="FatalReflectionException">
+ /// If the type does not have a zero-arg constructor.
+ /// </exception>
+ private ConstructorInfo GetZeroArgConstructorInfo(Type type)
+ {
+ const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
+ BindingFlags.Instance | BindingFlags.DeclaredOnly;
+
+ ConstructorInfo constructor = type.GetConstructor(flags, null, Type.EmptyTypes, null);
+ if (constructor == null)
+ {
+ throw new FatalReflectionException(string.Format(
+ CultureInfo.InvariantCulture, "Cannot instantiate a class that does not have a no-argument constructor [{0}].", type));
+ }
+ return constructor;
+ }
+
/// <summary>
/// Instantiate an instance of the object described by the supplied
|