示例#1
0
        /// <summary>
        /// Iterate through all DLLs in same location as the editor and load all non-abstract classes derived from NodeViewModel.
        /// </summary>
        public static void LoadNodeViewModels()
        {
            NodeViewModelsImpl.Clear();
            NodeViewModelLookup.Clear();

            // Go through each custom loaded type
            foreach (Type type in ExtensibilityUtils.Types)
            {
                if (!type.IsAbstract && type.IsSubclassOf(typeof(NodeViewModel)))
                {
                    NodeViewModelsImpl.Add(type);
                }
            }

            foreach (Type viewModel in NodeViewModelsImpl)
            {
                NodeViewModelAttribute viewModelAttribute = viewModel.GetCustomAttribute <NodeViewModelAttribute>();
                if (!NodeViewModelLookup.ContainsKey(viewModelAttribute.NodeType))
                {
                    NodeViewModelLookup.Add(viewModelAttribute.NodeType, (SpeechNode node) =>
                    {
                        return(Activator.CreateInstance(viewModel, node) as NodeViewModel);
                    });
                }
                else
                {
                    CelDebug.Fail("Duplicate view model type for node type " + viewModelAttribute.NodeType.Name);
                    continue;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Use the inputted node to create a view model from all the registered node view models.
        /// Returns null if no view model exists for the inputted node type.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static NodeViewModel CreateViewModel(SpeechNode node)
        {
            if (NodeViewModelLookup.ContainsKey(node.GetType()))
            {
                return(NodeViewModelLookup[node.GetType()](node) as NodeViewModel);
            }

            CelDebug.Fail("No node view model for inputted node type " + node.Name);
            return(null);
        }