Class DefaultViewLocator
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
Default implementation for IViewLocator. The default ViewModelToViewFunc behavior is to replace instances of "View" with "ViewMode" in the Fully Qualified Name of the ViewModel type.
public sealed class DefaultViewLocator : IViewLocator, IEnableLogger
- Inheritance
-
DefaultViewLocator
- Implements
- Extension Methods
Properties
ViewModelToViewFunc
Gets or sets a function that is used to convert a view model name to a proposed view name.
public Func<string, string> ViewModelToViewFunc { get; set; }
Property Value
Remarks
If unset, the default behavior is to change "ViewModel" to "View". If a different convention is followed, assign an appropriate function to this property.
Note that the name returned by the function is a starting point for view resolution. Variants on the name will be resolved according to the rules set out by the ResolveView<T>(T?, string?) method.
Methods
ResolveView<T>(T?, string?)
Returns the view associated with a view model, deriving the name of the type via ViewModelToViewFunc, then discovering it via the service locator.
public IViewFor? ResolveView<T>(T? viewModel, string? contract = null)
Parameters
viewModel
TThe view model whose associated view is to be resolved.
contract
stringOptional contract to be used when resolving from Splat.
Returns
- IViewFor
The view associated with the given view model.
Type Parameters
T
The type.
Remarks
Given view model type T
with runtime type RT
, this implementation will attempt to resolve the following views:
-
Look for a service registered under the type whose name is given to us by passing
RT
to ViewModelToViewFunc (which defaults to changing "ViewModel" to "View"). -
Look for a service registered under the type
IViewFor<RT>
. -
Look for a service registered under the type whose name is given to us by passing
T
to ViewModelToViewFunc (which defaults to changing "ViewModel" to "View"). -
Look for a service registered under the type
IViewFor<T>
. -
If
T
is an interface, change its name to that of a class (i.e. drop the leading "I"). If it's a class, change to an interface (i.e. add a leading "I"). - Repeat steps 1-4 with the type resolved from the modified name.