shapper said:
This works fine:
foreach (string key in routes.Keys.ToArray())
routes[key] = ((String)routes[key]).ToLower();
It's less efficient, but yes…you can do it that way too.
And I was trying to use this way:
routes = routes.ToDictionary(r => r.Key, r => (object)
((string)r.Value).ToLower());
That's completely different from the original question you asked.
But in fact my routes is not a Dictionary. Is a RouteValueDictionary
as follows:
Public Class RouteValueDictionary _
Implements IDictionary(Of String, Object), _
ICollection(Of KeyValuePair(Of String, Object)), IEnumerable(Of
KeyValuePair(Of String, Object)), _
IEnumerable
So I get the error:
Cannot implicitly convert type
'System.Collections.Generic.Dictionary<string,object>' to
'System.Web.Routing.RouteValueDictionary'
Does this has a solution?
Not unless you add something to your own code to convert a Dictionary to
a RouteValueDictionary.
Loop is ok to ... I was just wondering how to have this working with a
Lambda to.
The System.Linq.Enumerable class has never heard of your custom
RouteValueDictionary. You're not going to find a single method in the
class that returns that specific type.
Frankly, I suspect that it's a design mistake for you to have a custom
dictionary type. Most likely, your code would actually be better if
you'd just use the .NET System.Collections.Generic.Dictionary<TKey,
TValue> type, and of course if you did that then the Enumerable class
would work fine for you.
But it's impossible for me to say for sure without knowing more about
the overall design. I can only state the suspicion based on past
experience.
Barring that, then hopefully your own RouteValueDictionary type is
implemented as a container of an instance of Dictionary<TKey, TValue>.
In that case, it should be trivial for you to add a constructor or other
initializer to the type that takes as input an actual Dictionary<TKey,
TValue> instance and uses that instance for the internal dictionary
storage. You could even make that underlying storage typed as
IDictionary<TKey, TValue> instead, and allow the initialization to occur
with any arbitrary implementation of IDictionary<TKey, TValue> (such as
another instance of RouteValueDictionary, or similar type.
Pete