PDA

View Full Version : Problem with indexer.


zerg78
07-10-2006, 11:05 AM
Hello all!

I have 2 classes declarations:

using System;
using System.Collections.Generic;
using System.Text;

namespace FrontController
{
public class ControllerMapper : IControllerMapper
{
private IDictionary<string, string> handleDictionary = new Dictionary<string, string>();

public string this[string key]
{
get
{
return handleDictionary[key];
}
set
{
handleDictionary.Add(key, value);
}
}
}
}

/////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace FrontController
{
public class SimpleDispatcher : IDispatcher
{
private IControllerMapper handlerMapper;

public void Dispatch(HttpContext Context)
{

}


#region IoC

public IControllerMapper HandlerMapper
{
get
{
return handlerMapper;
}
set
{
handlerMapper = value;
}

}

#endregion
}
}

also I have web.xml declaration, presented below:

<object id="ControllerMapper" type="FrontController.ControllerMapper, FrontController">
<property name="Item[0]" value="value" />
</object>

<object id="Dispatcher" type="FrontController.SimpleDispatcher, FrontController">
<property name="ControllerMapper" ref="ControllerMapper"/>
</object>


after build and deploy I have message "Parameter count mismatch."
Where is problem? Help please.

Mark Pollack
07-19-2006, 10:54 PM
Hi,
Sorry for the late reply. At first glance I think that the change to using the expression evaluator for parsing property names introduced this bug, try out without the word "Item", that is just [0]. I'll explicitly reproduce it and get back to you.
Cheers,
Mark

Mark Pollack
07-20-2006, 12:54 AM
Hi,
I reproduced your issue, the fix I suggested didn't work. I'll dig into it more. Just wanted to update you.
Cheers,
Mark

Mark Pollack
08-11-2006, 04:31 PM
Hi,
I resolved your issue. The 'Item' notation is no longer working due to the switch to use the Spring.Expressions package, so you have to use just plain square brackets. This is a bug/change that we will fix. Since it is a string based accessor for the indexer you need to put single quotes around the zero in order for it to be recognized as a string instead of an integer. Also, there is a typo in the name of the property as declared in the definition of simple dispatcher, it should read 'name=HandlerMapper' instead of 'name="ControllerMapper". Here is the XML fragment that should solve your problem.


<object id="ControllerMapper" type="FrontController.ControllerMapper, FrontController">
<property name="['0]]" value="value" />
</object>

<object id="Dispatcher" type="FrontController.SimpleDispatcher, FrontController">
<property name="HandlerMapper" ref="ControllerMapper"/>
</object>


Hope this helps,

Cheers,
Mark

zerg78
09-06-2006, 02:34 PM
Thanks for you reply.
But I bypassed this problem by usage Map:
<property name="['[.]html$']" ref="JSCommand" />
where [.]html$ из maps key.
By the way in your sample code was used ['0]], may be more correct is usage of ['0]?