Ejemplo n.º 1
0
        /// <summary>
        /// Resolves the control tree.
        /// </summary>
        public virtual IAbstractTreeRoot ResolveTree(DothtmlRootNode root, string fileName)
        {
            var directives       = ProcessDirectives(root);
            var wrapperType      = ResolveWrapperType(directives, fileName);
            var viewModelType    = ResolveViewModelType(directives, root, fileName);
            var namespaceImports = ResolveNamespaceImports(directives, root);

            // We need to call BuildControlMetadata instead of ResolveControl. The control builder for the control doesn't have to be compiled yet so the
            // metadata would be incomplete and ResolveControl caches them internally. BuildControlMetadata just builds the metadata and the control is
            // actually resolved when the control builder is ready and the metadata are complete.
            var viewMetadata = controlResolver.BuildControlMetadata(CreateControlType(wrapperType, fileName));

            var dataContextTypeStack = CreateDataContextTypeStack(viewModelType, null, namespaceImports, new BindingExtensionParameter[] {
                new CurrentMarkupControlExtensionParameter(wrapperType),
                new BindingPageInfoExtensionParameter()
            });

            var view = treeBuilder.BuildTreeRoot(this, viewMetadata, root, dataContextTypeStack, directives);

            view.FileName = fileName;

            ResolveRootContent(root, view, viewMetadata);

            return(view);
        }
Ejemplo n.º 2
0
        public ResolvedTreeRoot ResolveTree(DothtmlRootNode root, string fileName)
        {
            var wrapperType = ResolveWrapperType(root, fileName.EndsWith(".dotcontrol", StringComparison.Ordinal) ? typeof(DotvvmMarkupControl) : typeof(DotvvmView));

            // We need to call BuildControlMetadata instead of ResolveControl. The control builder for the control doesn't have to be compiled yet so the
            // metadata would be incomplete and ResolveControl caches them internally. BuildControlMetadata just builds the metadata and the control is
            // actually resolved when the control builder is ready and the metadata are complete.
            var viewMetadata = controlResolver.BuildControlMetadata(new ControlType(wrapperType, virtualPath: fileName));
            var view         = new ResolvedTreeRoot(viewMetadata, root, null);

            foreach (var directive in root.Directives)
            {
                if (!string.Equals(directive.Name, Constants.BaseTypeDirective, StringComparison.InvariantCultureIgnoreCase))
                {
                    view.Directives.Add(directive.Name, directive.Value);
                }
            }

            ResolveViewModel(fileName, view, wrapperType);

            foreach (var node in root.Content)
            {
                view.Content.Add(ProcessNode(node, viewMetadata, view.DataContextTypeStack));
            }
            return(view);
        }