INavigationService, UriBuilder, WithParam and default value of a parameter (target property)

Topics: Bugs, Feature Requests, Framework Services
Oct 6, 2012 at 12:27 AM
Edited Oct 6, 2012 at 12:35 AM

Hello.

I've tried to make some stuff with navigation in my app with using of INavifationService. I've found a very strange behaviour of it. Example:

public class FirstViewModel
{
    public bool BoolProperty { get; set; }

    public string StringProperty { get; set; }

    // ...
}

public class SecondViewModel
{
    private readonly INavigationService _navigationService;
    
    private void Method()
    {
        _navigationService
            .UriFor<FirstViewModel>()
            .WithParam(x => x.BoolProperty, false)
            .WithParam(x => x.StringProperty, "parameter")
            .Navigate();
    }
    
    // ...
}

What uri will be formed? Correct answer:

/Views/FirstView.xaml?StringProperty=parameter

And where is BoolProperty?

I opened sources of Caliburn Micro and saw this code:

public class UriBuilder 
{
    // ...

    public UriBuilder WithParam(Expression> property, TValue value) 
    {
        if (!Equals(default(TValue), value)) 
        {
            queryString[property.GetMemberInfo().Name] = value.ToString();
        }

        return this;
    }

    // ...
}

So I found out that I can't use default values with a target property. And I think it's a very strange logic! Why I can't use default values? There is a lot of scenarios where default values can be used.

I believe that the source code of Caliburn Micro must be changed to remove checking of the equality in the WithParam method. Or can someone specify me the reason why the code such as it is?

Coordinator
Oct 6, 2012 at 4:02 AM

What purpose would there be in putting a default value in the query string? Setting it on the VM makes no difference. It's already going to be the default value.