PDA

View Full Version : constructor with params argument


erazor
09-16-2005, 09:28 AM
Hello

Below is an example of what I'm trying and I would like to know if this is possible at all or if there's a viable workaround.


public TestService(params string[] PermissionOverride)
{
}



<object name="TestService"
type="test.TestService, test.Facade"
singleton="false">
<constructor-arg index="0">
<value>value1</value>
</constructor-arg>
<constructor-arg index="1">
<value>value2</value>
</constructor-arg>
<constructor-arg index="2">
<value>valueN</value>
</constructor-arg>
</object>


As you can see I'm trying to pass a variable number of arguments to a constructor. Which doesn't work since Spring cannot find a constructor with a matching signature - which I tend to classify as a bug :)

Any comments?

Rick Evans
09-16-2005, 02:10 PM
Hi

I see where you are going with this. To be fair, I never considered that one would use individual <constructor-arg/> elements to define the individual arguments of a method / ctor that used a params-style argument.... so in that you have a valid point.

The way I tested for params-style arguments in the test suite was to simply pass a list of elements for the params-style argument. In the case of your example, there is only one constructor argument (a string[] array), and so one uses a single <constructor-arg/> element that has a <list/> element as its value. That will work, and that is the way that I tested the codebase... it never crossed my mind to do it the way you describe; this is not a slight on you, more a slight on me :)

I (or rather the Spring.NET team) can do one, or all, of two things...

Add more explicit documentation detailing how one passes arguments to methods / ctors that use a params-style parameter.
Add support for the usage-style that you have used in your post.
I haven't created a JIRA issue for this (yet)... I'll wait until more people have weighed in on this forum posting with their own thoughts. Please do post back... I'd be interested to hear your thoughts.

Cheerio
Rick

erazor
09-16-2005, 02:24 PM
Hi

I see where you are going with this. To be fair, I never considered that one would use individual <constructor-arg/> elements to define the individual arguments of a method / ctor that used a params-style argument.... so in that you have a valid point.

The way I tested for params-style arguments in the test suite was to simply pass a list of elements for the params-style argument. In the case of your example, there is only one constructor argument (a string[] array), and so one uses a single <constructor-arg/> element that has a <list/> element as its value. That will work, and that is the way that I tested the codebase... it never crossed my mind to do it the way you describe; this is not a slight on you, more a slight on me :)

I (or rather the Spring.NET team) can do one, or all, of two things...

Add more explicit documentation detailing how one passes arguments to methods / ctors that use a params-style parameter.
Add support for the usage-style that you have used in your post.
I haven't created a JIRA issue for this (yet)... I'll wait until more people have weighed in on this forum posting with their own thoughts. Please do post back... I'd be interested to hear your thoughts.

Cheerio
Rick

Thanks for your quick reply Rick!

As usual just when somebody answers your post you probably have figured it out yourself :)

I came to the same solution as you suggested by examining the spring.net xsd scheme.

Aleks Seovic
09-20-2005, 04:34 PM
I think leaving implementation the way it is and adding necessary documentation is the way to go in this case.

Methods with params argument do expect an array of the specified type, so that's what config file should reflect.

- Aleks

Rick Evans
09-20-2005, 04:41 PM
Created a JIRA entry (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-191) to address the issue.

I'll see to it it this weekend if someone doesn't come along and pick this most low hanging of fruits before then.

Ciao
Rick