Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var div       = new DivElement();
            var paragraph = new PElement();
            var br        = new BrElement();
            var text      = new TextElement("Example text");
            var image     = new ImageElement();

            image.SetAttribute("src", "http://opensourceforu.com/wp-content/uploads/2016/03/Microsoft.png");
            paragraph.Add(text);
            paragraph.Add(br);
            div.Add(image);
            div.Add(paragraph);

            Console.WriteLine("Render div:");
            Console.Write(div.Render());

            Console.WriteLine("Render paragraph:");
            Console.Write(paragraph.Render());

            Console.WriteLine("It works");
        }
Ejemplo n.º 2
0
        public static new Element FromObj(object instance)
        {
            if (instance == null)
            {
                return(null);
            }
            try{
                string tagUrn  = (string)GetProperty(instance, "tagUrn");
                string tagName = (string)GetProperty(instance, "tagName");
                if (tagUrn == null || tagUrn == "")
                {
                    switch (tagName.ToLower())
                    {
                    case "!":                       return(CommentElement.FromObj(instance));

                    case "a":                       return(AElement.FromObj(instance));

                    case "area":            return(AreaElement.FromObj(instance));

                    case "base":            return(BaseElement.FromObj(instance));

                    case "basefont":        return(BaseFontElement.FromObj(instance));

                    case "bgsound":         return(BgsoundElement.FromObj(instance));

                    case "address":
                    case "pre":
                    case "center":
                    case "listing":
                    case "xmp":
                    case "plaintext":
                    case "blockquote":      return(BlockElement.FromObj(instance));

                    case "body":            return(BodyElement.FromObj(instance));

                    case "br":                      return(BrElement.FromObj(instance));

                    case "button":          return(ButtonElement.FromObj(instance));

                    case "dd":                      return(DdElement.FromObj(instance));

                    case "div":                     return(DivElement.FromObj(instance));

                    case "dl":                      return(DlElement.FromObj(instance));

                    case "dt":                      return(DtElement.FromObj(instance));

                    case "embed":           return(EmbedElement.FromObj(instance));

                    case "fieldset":        return(FieldsetElement.FromObj(instance));

                    case "font":            return(FontElement.FromObj(instance));

                    case "form":            return(FormElement.FromObj(instance));

                    case "frame":           return(FrameElement.FromObj(instance));

                    case "frameset":        return(FramesetElement.FromObj(instance));

                    case "head":            return(HeadElement.FromObj(instance));

                    case "h1":
                    case "h2":
                    case "h3":
                    case "h4":
                    case "h5":
                    case "h6":
                        return(HnElement.FromObj(instance));

                    case "hr":                      return(HrElement.FromObj(instance));

                    case "html":            return(HtmlElement.FromObj(instance));

                    case "iframe":          return(IframeElement.FromObj(instance));

                    case "img":                     return(ImgElement.FromObj(instance));

                    case "input":           return(InputElement.FromObj(instance));

                    case "isindex":         return(IsindexElement.FromObj(instance));

                    case "legend":          return(LegendElement.FromObj(instance));

                    case "label":           return(LabelElement.FromObj(instance));

                    case "li":                      return(LiElement.FromObj(instance));

                    case "link":            return(LinkElement.FromObj(instance));

                    case "map":                     return(MapElement.FromObj(instance));

                    case "marquee":         return(MarqueeElement.FromObj(instance));

                    case "meta":            return(MetaElement.FromObj(instance));

                    case "nextid":          return(NextidElement.FromObj(instance));

                    case "noembed":
                    case "noframes":
                    case "nolayer":
                    case "noscript":        return(NoshowElement.FromObj(instance));

                    case "applet":
                    case "object":          return(ObjectElement.FromObj(instance));

                    case "ol":                      return(OlElement.FromObj(instance));

                    case "optgroup":
                    case "option":          return(OptionElement.FromObj(instance));

                    case "p":                       return(PElement.FromObj(instance));

                    case "param":           return(ParamElement.FromObj(instance));

                    case "i":
                    case "u":
                    case "b":
                    case "q":
                    case "s":
                    case "strong":
                    case "del":
                    case "strike":
                    case "em":
                    case "small":
                    case "big":
                    case "ruby":
                    case "rp":
                    case "sub":
                    case "sup":
                    case "acronym":
                    case "bdo":
                    case "cite":
                    case "dfn":
                    case "ins":
                    case "code":
                    case "kbd":
                    case "samp":
                    case "var":
                    case "nobr":            return(PhraseElement.FromObj(instance));

                    case "script":          return(ScriptElement.FromObj(instance));

                    case "select":          return(SelectElement.FromObj(instance));

                    case "span":            return(SpanElement.FromObj(instance));

                    case "style":           return(StyleElement.FromObj(instance));

                    case "caption":         return(CaptionElement.FromObj(instance));

                    case "td":
                    case "th":                      return(TableCellElement.FromObj(instance));

                    case "table":           return(TableElement.FromObj(instance));

                    case "colgroup":
                    case "col":                     return(ColElement.FromObj(instance));

                    case "tr":                      return(TrElement.FromObj(instance));

                    case "thead":
                    case "tbody":
                    case "tfoot":           return(TableSectionElement.FromObj(instance));

                    case "textarea":        return(TextAreaElement.FromObj(instance));

                    case "wbr": return(TextElement.FromObj(instance));

                    case "title":           return(TitleElement.FromObj(instance));

                    case "dir":
                    case "menu":
                    case "ul":                      return(UlElement.FromObj(instance));
                        // optionbutton ?
                        // spanflow ?
                        // default:			return UnknownElement.FromObj(instance);
                    }
                }
            }catch {
                // IHTMLElement でない可能性
            }

            return(new Element(instance));
        }