当前位置: 首页>>代码示例>>C#>>正文


C# ViewModel.GetType方法代码示例

本文整理汇总了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()]();
        }
开发者ID:bfriesen,项目名称:BadSnowstorm,代码行数:16,代码来源:DefaultViewFactory.cs

示例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", ""));
 }
开发者ID:wang-yichun,项目名称:RunningGuyTut,代码行数:13,代码来源:ViewResolver.cs

示例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);
			}
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:21,代码来源:PropertyInfoDictionary.cs

示例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;
        }
开发者ID:samueldjack,项目名称:CrunchAPIExplorer,代码行数:38,代码来源:ViewLocator.cs

示例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;
 }
开发者ID:trommlbomml,项目名称:ImageShrinker,代码行数:9,代码来源:ViewService.cs

示例6: AddViewModel

 public void AddViewModel(string vmName, ViewModel viewModel, string targetBinding = "", string jsFunctionName = "")
 {
     _viewModelsToAdd.Add(new ViewModelToAdd(vmName, viewModel.GetType(), targetBinding, jsFunctionName));
     _initialValues = viewModel;
 }
开发者ID:afinzel,项目名称:KnockoutCreator,代码行数:5,代码来源:KoCreator.cs

示例7: Bind

		/// <summary>
		/// ビューモデルの登録
		/// </summary>
		/// <param name="vm">Vm.</param>
		public void Bind(ViewModel vm)
		{
			string key = vm.GetType().Name;
			ViewModels[key] = vm;
		}
开发者ID:K-Yoshiki,项目名称:menko,代码行数:9,代码来源:ViewRoot.cs


注:本文中的ViewModel.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。