private static object CreateTemplate(object obj, string templatePropertyName) { var code = GetTemplateCode(obj, templatePropertyName); if (code == null) { return(null); } XmlnsDictionary.New(); //模板内的加载,需要使用自己的xmlns空间 #if (DEBUG) FrameworkTemplate.PushTrackCode(code); object template = XamlReader.ReadComponent(code); FrameworkTemplate.PopTrackCode(); #endif #if (!DEBUG) object template = XamlReader.ReadComponent(code); #endif XmlnsDictionary.Pop(); //if (template == null) throw new WebException("没有找到类型" + objType.FullName + "的模板" + templatePropertyName + "定义"); if (template == null) { return(null); } return(template); }
/// <summary> /// 根据节点名称得到类型 /// </summary> /// <param name="node"></param> /// <returns></returns> private static Type GetComponentTypeByTagName(HtmlNode node) { var xmlns = XmlnsDictionary.Collect(node); var xamlNamespace = xmlns.GetXamlNamespace(node.Name); return(ComponentTypeLocator.Locate(xamlNamespace, node.Name) ?? HtmlElement.Type); }
/// <summary> /// 从节点中收集命名空间信息 /// </summary> /// <param name="node"></param> internal static XmlnsDictionary Collect(HtmlNode node) { XmlnsDictionary xmlns = Current; if (node == null) { return(xmlns); } var attributes = node.Attributes; if (attributes.Count > 0) { foreach (var attr in attributes) { if (attr.Name != null && (attr.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase) || attr.Name.StartsWith("xmlns:"))) { if (xmlns.Contains(attr.Name)) { continue; } xmlns.Add(attr.Name, attr.Value); } } } return(xmlns); }