Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

Commented Unassigned: WithParam ignores non-default values [317]

$
0
0
The WithParam method on UriBuilder ignores the parameter request if the value is default(T) where T is the parameter type.

This means that any target property that is initialized to a non-default value will not get set.

For example. Lets say we have a MainPage and a DetailPage and we call something like

```
navService.UriFor<DetailsPageViewModel>()
.WithParam(vm => vm.ShowHeader, false)
.Navigate();
```

The above parameter request will never make it onto the querystring due to the requested value being default(bool). Now if the default for the ShowHeader property is set to true then we have an undesired outcome.

The code that causes this is UriBuilder.cs#23:

```
if (!Equals(default(TValue), value)) {
queryString[property.GetMemberInfo().Name] = value.ToString();
}
```

Maybe something like the following to fix the issue for booleans etc but still keep the existing behavior for reference types so as not to confuse nulls with anything else like empty string?

```
#if WinRT
if (!Equals(default(TValue), value) || typeof(TValue).GetTypeInfo().IsValueType) {
#else
if (!Equals(default(TValue), value) || typeof(TValue).IsValueType) {
#endif
queryString[property.GetMemberInfo().Name] = value.ToString();
}
```
Comments: It could also be fixed by this code: ``` C# if (!ReferenceEquals(null, value)) { queryString[property.GetMemberInfo().Name] = value.ToString(); } ```

Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>