Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3066/Util
Modified Files:
ReflectionUtils.cs
Log Message:
Problems with Attributes in proxy generation [SPRNET-606]
Index: ReflectionUtils.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/ReflectionUtils.cs,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** ReflectionUtils.cs 3 Dec 2007 09:07:18 -0000 1.53
--- ReflectionUtils.cs 3 Dec 2007 23:31:28 -0000 1.54
***************
*** 730,733 ****
--- 730,734 ----
IList getSetValues = new ArrayList();
IList readOnlyProps = new ArrayList();
+ IList readOnlyValues = new ArrayList();
foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
***************
*** 753,756 ****
--- 754,758 ----
{
readOnlyProps.Add(pi);
+ readOnlyValues.Add(pi.GetValue(sourceAttribute, null));
}
}
***************
*** 761,769 ****
PropertyInfo pi = readOnlyProps[0] as PropertyInfo;
ConstructorInfo ciTemp = type.GetConstructor(new Type[1] {pi.PropertyType});
! if (ciTemp != null)
! {
! ci = ciTemp;
! ctorArgs = new object[1] {pi.GetValue(sourceAttribute, null)};
! }
}
--- 763,780 ----
PropertyInfo pi = readOnlyProps[0] as PropertyInfo;
ConstructorInfo ciTemp = type.GetConstructor(new Type[1] {pi.PropertyType});
! if (ciTemp != null)
! {
! ci = ciTemp;
! ctorArgs = new object[1] { readOnlyValues[0] };
! }
! else
! {
! ciTemp = type.GetConstructor(new Type[1] { readOnlyValues[0].GetType() });
! if (ciTemp != null)
! {
! ci = ciTemp;
! ctorArgs = new object[1] { readOnlyValues[0] };
! }
! }
}
***************
*** 862,866 ****
{
parameterTypes[i] = attributeData.ConstructorArguments[i].ArgumentType;
! parameterValues[i] = attributeData.ConstructorArguments[i].Value;
}
--- 873,877 ----
{
parameterTypes[i] = attributeData.ConstructorArguments[i].ArgumentType;
! parameterValues[i] = ConvertValueIfNecessary(attributeData.ConstructorArguments[i].Value);
}
***************
*** 868,871 ****
--- 879,883 ----
PropertyInfo[] attributeProperties = attributeType.GetProperties(
BindingFlags.Instance | BindingFlags.Public);
+
// Not using generics bellow as probably Spring.NET tries to keep
// it on .NET1 compatibility level right now I believe (SD)
***************
*** 885,889 ****
{
propertiesToSet.Add(attributeProperties[j]);
! namedParameterValues[k++] = ResolveValues(namedArgument.TypedValue.Value);
break;
}
--- 897,901 ----
{
propertiesToSet.Add(attributeProperties[j]);
! namedParameterValues[k++] = ConvertValueIfNecessary(namedArgument.TypedValue.Value);
break;
}
***************
*** 903,907 ****
}
}
-
// Get constructor corresponding to the parameters and their types
ConstructorInfo constructor = attributeType.GetConstructor(parameterTypes);
--- 915,918 ----
***************
*** 914,918 ****
}
! private static object ResolveValues(object value)
{
if (value == null) return value;
--- 925,929 ----
}
! private static object ConvertValueIfNecessary(object value)
{
if (value == null) return value;
***************
*** 925,943 ****
Type underlyingType = null; // type to be used for arguments
! Type listType = null;
! object list = null;
! List<int> prototypeList = new List<int>();
!
! foreach (CustomAttributeTypedArgument typedArgument in sourceArray)
{
if (underlyingType == null)
{
! underlyingType = typedArgument.ArgumentType;
!
! listType = Type.GetType(
! "System.Collections.Generic.List`1[[" + underlyingType.AssemblyQualifiedName + "]], " + prototypeList.GetType().Assembly.FullName, true, false);
! list = Activator.CreateInstance(listType);
}
! if (!underlyingType.Equals(typedArgument.ArgumentType))
{
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
--- 936,948 ----
Type underlyingType = null; // type to be used for arguments
! Array returnArray = null;
! for (int i = 0; i < sourceArray.Count; i++)
{
if (underlyingType == null)
{
! underlyingType = sourceArray[i].ArgumentType;
! returnArray = Array.CreateInstance(underlyingType, sourceArray.Count);
}
! if (!underlyingType.Equals(sourceArray[i].ArgumentType))
{
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
***************
*** 945,956 ****
}
! MethodInfo addMethod = listType.GetMethod("Add");
! object[] addMethodParameters = new object[1];
! addMethodParameters[0] = typedArgument.Value;
! addMethod.Invoke(list, addMethodParameters);
}
! MethodInfo toArrayMethod = listType.GetMethod("ToArray");
! return toArrayMethod.Invoke(list, new object[] { });
}
#endif
--- 950,958 ----
}
! returnArray.SetValue(sourceArray[i].Value, i);
}
! return returnArray;
!
}
#endif
|