Why is DictHelper casting all object values to String ?

0 views
Skip to first unread message

jsimons

unread,
Oct 24, 2008, 8:03:02 PM10/24/08
to Castle Project Development List
Hi,

The DictHelper class at the moment is casting all values added to its
internal dictionary to strings.
Does anyone know of any reason why?

If there isn't one, I would like to submit a patch so that it removes
the casting and allows to store any object types.

The reason for this is so that we can use it in situations like:
$Url.For($Dict.CreateN("action", "myaction").N("controller",
"mycontroller").N("querystring", $Dict.CreateN("t", "param1").N("s",
"param2")))
or
$Url.For($Dict.CreateN("action", "myaction").N("controller",
"mycontroller").N("params", $Dict.CreateN("t", "param1").N("s",
"param2")))

Cheers
John

James Curran

unread,
Oct 24, 2008, 9:12:37 PM10/24/08
to castle-pro...@googlegroups.com
Mainly because, originally, you created an entries with
Create("action=myaction","controller=mycontroller");

This led to people doing things like Create("ID="+id.ToString()); so
I added the N() syntax to simplify things. But, since they were both
strings before, so I kept them strings in the patch.

Also, I believe the very original purpose was to create query strings,
which were, by necessity, strings.

--
Truth,
James

On Fri, Oct 24, 2008 at 8:03 PM, jsimons <johnsi...@yahoo.com.au> wrote:

> The DictHelper class at the moment is casting all values added to its
> internal dictionary to strings.

> The reason for this is so that we can use it in situations like:

jsimons

unread,
Oct 24, 2008, 9:37:24 PM10/24/08
to Castle Project Development List
but if that is the reason why is the N and CreateN method signature:
(string key, object value) ?

at the moment a simple test like this breaks:

[Test]
public void MyBrokenTest()
{
IDictionary dict = DictHelper.CreateN("int", 1).N("bool", true);

Assert.AreEqual(1, dict["int"]);
Assert.AreEqual(true, bool);
}

As a consumer of this class I was expecting this test to pass.

I guess we could either:
1. change the methods signature to (string key, string value) -> this
is a breaking change
2. allow objects to be stored in the dictionary by removing the
ToString cast -> this would not break the interface

thoughts?

On Oct 25, 12:12 pm, "James Curran" <james.cur...@gmail.com> wrote:
> Mainly because, originally, you created an entries with
> Create("action=myaction","controller=mycontroller");
>
> This led to people doing things like Create("ID="+id.ToString());  so
> I added the N() syntax to simplify things. But, since they were both
> strings before, so I kept them strings in the patch.
>
> Also, I believe the very original purpose was to create query strings,
> which were, by necessity, strings.
>
> --
> Truth,
>     James
>

jsimons

unread,
Oct 24, 2008, 9:40:04 PM10/24/08
to Castle Project Development List
oops made a mistake on the test:
[Test]
public void MyBrokenTest()
{
IDictionary dict = DictHelper.CreateN("int",
1).N("bool", true);

Assert.AreEqual(1, dict["int"]);
Assert.AreEqual(true, dict["bool"]);

Gildas

unread,
Oct 25, 2008, 6:03:32 AM10/25/08
to Castle Project Development List
I had problems with this too.

Take the "ajax" prefixed options of the Jquery validation generator as
an example. This is the reason why the options are prefixed. At first,
I wanted a sub dictionary with those options.

jsimons

unread,
Oct 26, 2008, 4:30:48 PM10/26/08
to Castle Project Development List
I've submitted a patch to fix this issue:
http://support.castleproject.org/projects/MR/issues/view/MR-ISSUE-501
Can someone please have a look at it.

Cheers
John
Reply all
Reply to author
Forward
0 new messages