本文整理汇总了C#中ViewModel.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ViewModel.GetType方法的具体用法?C# ViewModel.GetType怎么用?C# ViewModel.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ViewModel
的用法示例。
在下文中一共展示了ViewModel.GetType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateView
public IView CreateView(ViewModel viewModel)
{
if (!_factoryMethods.ContainsKey(viewModel.GetType()))
{
// If the viewModel type is unknown, it is technically possible that an assembly was loaded after we last checked, so reinitialize.
InitializeViewFactory();
if (!_factoryMethods.ContainsKey(viewModel.GetType()))
{
// Ok, we really, *really* tried to find the view. Sorry about the exception. :(
throw new Exception(String.Format("Unable to locate a View that corresponds to ViewModel type: {0}.", viewModel.GetType()));
}
}
return _factoryMethods[viewModel.GetType()]();
}
示例2: FindView
/// <summary>
/// Provides a prefab
/// </summary>
/// <param name="model">The model for the view prefab we are looking for</param>
/// <returns></returns>
public virtual GameObject FindView(ViewModel model)
{
if (model == null)
{
throw new ArgumentNullException("model");
}
return FindView(model.GetType().Name.Replace("ViewModel", ""));
}
示例3: PropertyInfoDictionary
public PropertyInfoDictionary(ViewModel viewModel)
{
this.viewModel = viewModel;
currentViewModelType = viewModel.GetType();
var properties = GetPropertiesExcludingCommand();
foreach (var property in properties)
{
var propertyName = property.Name;
if (propertyInfoDictionary.ContainsKey(propertyName))
{
const string Message = "The property '{0}' of the ViewModel '{1}' is already declared in a base class.";
throw new InvalidOperationException(string.Format(Message, propertyName, currentViewModelType.Name));
}
propertyInfoDictionary.Add(propertyName, property);
}
}
示例4: CreateViewForViewModel
public FrameworkElement CreateViewForViewModel(ViewModel viewModel)
{
var viewModelType = viewModel.GetType();
var viewModelNamespace = viewModelType.Namespace;
if (!viewModelNamespace.EndsWith(".ViewModels"))
{
throw new InvalidOperationException("Expected ViewModel to be located in a namespace ending with '.ViewModels'");
}
var viewsNamespace = viewModelNamespace.Substring(0, viewModelNamespace.Length - "ViewModels".Length)
+ "Views";
var viewModelTypeName = viewModelType.Name;
if (!viewModelTypeName.EndsWith("ViewModel"))
{
throw new InvalidOperationException("Expected ViewModel name to end with 'ViewModel'");
}
var viewTypeName = viewModelTypeName.Substring(0, viewModelTypeName.Length - "ViewModel".Length)
+ "View";
var expectedFullTypeName = viewsNamespace + "." + viewTypeName;
var type = Type.GetType(expectedFullTypeName);
if (type == null)
{
throw new InvalidOperationException(string.Format("No corresponding View was found for '{0}. Tried '{1}'", viewModelType.FullName, expectedFullTypeName));
}
var instance = Activator.CreateInstance(type) as FrameworkElement;
if (instance == null)
{
throw new InvalidOperationException(string.Format("Expected '{0}' to be derived from FrameworkElement", expectedFullTypeName));
}
return instance;
}
示例5: GetWindowForViewModel
private static Type GetWindowForViewModel(ViewModel viewModel)
{
Type windowType;
if (!ViewModelToWindowMapping.TryGetValue(viewModel.GetType(), out windowType))
{
throw new ArgumentException("No Window for ViewModel Type " + viewModel.GetType().FullName);
}
return windowType;
}
示例6: AddViewModel
public void AddViewModel(string vmName, ViewModel viewModel, string targetBinding = "", string jsFunctionName = "")
{
_viewModelsToAdd.Add(new ViewModelToAdd(vmName, viewModel.GetType(), targetBinding, jsFunctionName));
_initialValues = viewModel;
}
示例7: Bind
/// <summary>
/// ビューモデルの登録
/// </summary>
/// <param name="vm">Vm.</param>
public void Bind(ViewModel vm)
{
string key = vm.GetType().Name;
ViewModels[key] = vm;
}