예제 #1
0
        private void DetectElement(string source)
        {
            source = source.Substring(1, source.Length - 2);
            var tag   = source.Split(' ').First().ToLower();
            var attrs = ResolveAttributes(source, tag);

            if (RuleActions.ContainsKey(tag))
            {
                var action = RuleActions[tag];
                action.Invoke(tag, attrs);
            }
            else if (tag.FirstOrDefault() == '/')
            {
                var element = OpennedElements.Pop();
            }
            else if (source.LastOrDefault() == '/')
            {
                var elementType     = DomElements[tag];
                var elementInstance = Activator.CreateInstance(elementType) as HTMLElement;

                if (elementInstance != null)
                {
                    elementInstance.IsNeedClose = false;
                }

                ResolveElement(elementInstance, elementType, tag, attrs);
            }
            else if (DomElements.ContainsKey(tag))
            {
                var elementType     = DomElements[tag];
                var elementInstance = Activator.CreateInstance(elementType) as HTMLElement;

                ResolveElement(elementInstance, elementType, tag, attrs);
            }
        }
예제 #2
0
        private void AddRule <T>() where T : class
        {
            var type      = typeof(T);
            var attribute = type.GetCustomAttributes(typeof(HtmlNameAttribute), false).FirstOrDefault() as HtmlNameAttribute;

            if (attribute != null)
            {
                var name = attribute.Name;

                DomElements.Add(name, type);
            }
            else
            {
                throw new ArgumentException();
            }
        }