示例#1
0
        private Data.Element ParseElement(Core.Element template, Data.Element parent)
        {
            var attributes = ReadAttributes(reader);

            if (!TryGetElementType(template, attributes, elementBaseType, out var ownerType, out var className))
            {
                throw new Exception($"Failed to get type {className}");
            }

            var typeInfo = ElementRegistry.GetElementType(ownerType);

            var namespaces = attributes
                             .Where(p => NamespaceAttribute.IsNamespaceKey(p.Value) && NamespaceAttribute.IsCLRNamespace(p.Value))
                             .Select(p => NamespaceAttribute.Parse(p.Value).Value)
                             .ToList();

            if (parent == null && schema.namespaces != null)
            {
                namespaces.Add(schema.namespaces);
            }

            var nsHierarchy = GetElementChain(parent)
                              .SelectMany(e => e.namespaces)
                              .Concat(namespaces);

            var properties = attributes
                             .Where(p => typeInfo.hierarchyProps.ContainsKey(p.Key, nsHierarchy))
                             .ToDictionary(p => p.Key, p => p.Value);

            var events = attributes
                         .Where(p => EventManager.HasRoutedEvent(p.Key, ownerType, nsHierarchy))
                         .ToDictionary(p => p.Key, p => p.Value);

            return(new Data.Element
            {
                parent = parent,
                name = reader.Name,
                className = className,
                type = ownerType,
                rawAttributes = attributes,
                properties = properties,
                events = events,
                namespaces = namespaces
            });
        }
示例#2
0
 public void OnEnable()
 {
     elemInfo = ElementRegistry.GetElementType(target.GetType());
 }