Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4311
Modified Files:
AttributeUtils.cs
Log Message:
SPRNET-606 Problems with Attributes in proxy generation - fix for regression bug copying Spring Transaction attributes, add unit test for this case.
Clean up misc documentation in code.
Index: AttributeUtils.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/AttributeUtils.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** AttributeUtils.cs 16 Oct 2007 00:28:49 -0000 1.2
--- AttributeUtils.cs 21 Oct 2007 18:16:32 -0000 1.3
***************
*** 24,27 ****
--- 24,28 ----
using System.Collections;
using System.Collections.Generic;
+ using System.Collections.ObjectModel;
using System.Globalization;
using System.Reflection;
***************
*** 264,268 ****
{
propertiesToSet.Add(attributeProperties[j]);
! namedParameterValues[k++] = namedArgument.TypedValue.Value;
// The bellow few lines are only for testing purposes
--- 265,269 ----
{
propertiesToSet.Add(attributeProperties[j]);
! namedParameterValues[k++] = ResolveValues(namedArgument.TypedValue.Value);
// The bellow few lines are only for testing purposes
***************
*** 300,303 ****
--- 301,350 ----
}
+ private static object ResolveValues(object value)
+ {
+ if (value == null) return value;
+
+ // We are only hunting for the case of the ReadOnlyCollection<T> here.
+ ReadOnlyCollection<CustomAttributeTypedArgument> sourceArray =
+ value as ReadOnlyCollection<CustomAttributeTypedArgument>;
+
+ if (sourceArray == null) return value;
+
+ 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,
+ "Types for the same named parameter of array type are expected to be same"));
+ }
+
+ 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[]{});
+
+ }
+
|