From: max toro q <maxtoroq@gm...> - 2008-07-12 22:23:49
I realized the problem is not with ICollection, but with IDictionary
(which derives from ICollection).
The feature of converting -any- collection to a sequence is good,
-except- with IDictionary. The main use case of dictionaries is to get
and set values by key, you tipically don't want to deal with the whole
collection of values.
The good part is that IDictionary defines 2 properties, Keys and
Values, both of type ICollection, which you can use if you want a
sequence of all keys/values, that should make everyone happy, right?
> Message: 2
> Date: Fri, 11 Jul 2008 23:18:46 +0100
> From: "Michael Kay" <mike@...>
> Subject: Re: [saxon] Converting the Result of a .NET Extension
> To: "'Mailing list for the SAXON XSLT and XQuery processor'"
> Message-ID: <6EF00EA45A4D4EA98906D3548864BEE1@...>
> Content-Type: text/plain; charset="us-ascii"
> The design is clearly a compromise, but I don't accept that it's wrong. For
> many use cases it's very convenient that if an extension function returns a
> collection of strings, the stylesheet or query can process the returned
> value as a sequence of strings. Cross-language programming across dissimilar
> type systems is never going to be perfect. As you say, there's a workaround
> which is to supply a wrapper class that provides the methods you need.
> Michael Kay
>> -----Original Message-----
>> From: saxon-help-bounces@...
>> [mailto:saxon-help-bounces@...] On Behalf
>> Of max toro q
>> Sent: 11 July 2008 23:06
>> To: saxon-help@...
>> Subject: [saxon] Converting the Result of a .NET Extension Function
>> Hello Michael,
>> "If the returned value is an instance of the .NET interface
>> System.Collections.ICollection, or if it is an array, the
>> XPath value will be the sequence represented by the contents
>> of this collection or array. The members of the list or array
>> will each be converted to an XPath value, as if each member
>> was supplied from a separate function call. An error is
>> reported if the result contains a list or array nested within
>> another list or array. The contents of the list or array are
>> copied immediately on return from the function, so the
>> original collection or array object itself may be safely re-used."
>> I think this behaviour is very wrong, because:
>> - You cannot get only 1 item of an ICollection.
>> - You cannot access instance level methods or properties of
>> an ICollection, for instance Add, Remove, Count or other
>> type-specific members.
>> I'm trying to use instance level members of the QueryString
>> and Form properties of the System.Web.HttpRequest object,
>> also the Session property of the System.Web.HttpContext
>> object. The idea is being able to get, set and remove objects
>> by key or index.
>> I know the workaround, write a class that would act as a
>> gateway to all the functionality I need. However I still
>> think the processor should return the "wrapped object" for
>> ICollection(s), and apply the conversion-to-a-sequence only
>> to arrays (System.Array is a special class which you cannot
>> derive from).
>> max toro q