Caliburn.Micro.FrameAdapter.TryInjectQueryString C# (CSharp) Method

TryInjectQueryString() protected method

Attempts to inject query string parameters from the view into the view model.
protected TryInjectQueryString ( object viewModel, object view ) : void
viewModel object The view model.
view object The view.
return void
        protected virtual void TryInjectQueryString(object viewModel, object view) 
        {
            var page = view as Page;
            if (page == null)
                return;

            var viewModelType = viewModel.GetType();

            foreach(var pair in page.NavigationContext.QueryString)
            {
                var property = viewModelType.GetProperty(pair.Key);
                if(property == null)
                    continue;

                property.SetValue(viewModel, MessageBinder.CoerceValue(property.PropertyType, pair.Value), null);
            }
        }