From 592b7e4bc22d7d2b2590b2598ee85b03b3e9f38a Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Wed, 14 Jun 2017 23:20:51 -0700 Subject: [PATCH] Remove Mapping class --- Ooui/Button.cs | 2 ++ Ooui/Div.cs | 4 ++++ Ooui/Element.cs | 5 +++++ Ooui/EventTarget.cs | 9 +++++---- Ooui/FormControl.cs | 5 +++++ Ooui/Mapping.cs | 36 ------------------------------------ Ooui/Node.cs | 6 +++--- Ooui/TextNode.cs | 2 ++ Tests/ButtonTests.cs | 1 + 9 files changed, 27 insertions(+), 43 deletions(-) delete mode 100644 Ooui/Mapping.cs diff --git a/Ooui/Button.cs b/Ooui/Button.cs index 8027c6b..6fdd9b1 100644 --- a/Ooui/Button.cs +++ b/Ooui/Button.cs @@ -22,10 +22,12 @@ namespace Ooui } public Button () + : base ("button") { } public Button (string text) + : this () { Text = text; } diff --git a/Ooui/Div.cs b/Ooui/Div.cs index 5302215..02012c5 100644 --- a/Ooui/Div.cs +++ b/Ooui/Div.cs @@ -4,5 +4,9 @@ namespace Ooui { public class Div : Element { + public Div () + : base ("div") + { + } } } diff --git a/Ooui/Element.cs b/Ooui/Element.cs index 0f53ec2..cdbb38a 100644 --- a/Ooui/Element.cs +++ b/Ooui/Element.cs @@ -4,6 +4,11 @@ namespace Ooui { public abstract class Element : Node { + protected Element (string tagName) + : base (tagName) + { + } + string className = ""; public string ClassName { get => className; diff --git a/Ooui/EventTarget.cs b/Ooui/EventTarget.cs index 9dc5bd9..f3a0806 100644 --- a/Ooui/EventTarget.cs +++ b/Ooui/EventTarget.cs @@ -13,15 +13,16 @@ namespace Ooui public string Id { get; private set; } = GenerateId (); - public Mapping Mapping { get; private set; } + public string TagName { get; private set; } public event Action MessageSent; public IEnumerable StateMessages => stateMessages; - public EventTarget () + protected EventTarget (string tagName) { - Mapping = Mapping.Get (GetType ()); + TagName = tagName; + SendCreate (); } public void AddEventListener (string eventType, EventHandler handler) @@ -82,7 +83,7 @@ namespace Ooui Send (new Message { MessageType = MessageType.Create, TargetId = Id, - Key = Mapping.TagName, + Key = TagName, }); } diff --git a/Ooui/FormControl.cs b/Ooui/FormControl.cs index 1b5611b..055b471 100644 --- a/Ooui/FormControl.cs +++ b/Ooui/FormControl.cs @@ -9,5 +9,10 @@ namespace Ooui get => name; set => SetProperty (ref name, value, "name"); } + + public FormControl (string tagName) + : base (tagName) + { + } } } diff --git a/Ooui/Mapping.cs b/Ooui/Mapping.cs deleted file mode 100644 index 13575b8..0000000 --- a/Ooui/Mapping.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Ooui -{ - public class Mapping - { - readonly Type type; - public string TagName { get; private set; } - - public Mapping (Type type) - { - this.type = type; - TagName = type.Name.ToLowerInvariant (); - } - - public string GetMemberPath (string propertyName) - { - return propertyName.ToLowerInvariant (); - } - - static readonly Dictionary mappings = - new Dictionary (); - - public static Mapping Get (Type type) - { - var key = type.FullName; - Mapping m; - if (!mappings.TryGetValue (key, out m)) { - m = new Mapping (type); - mappings[key] = m; - } - return m; - } - } -} diff --git a/Ooui/Node.cs b/Ooui/Node.cs index 62896a0..23b2bb4 100644 --- a/Ooui/Node.cs +++ b/Ooui/Node.cs @@ -20,9 +20,9 @@ namespace Ooui } } - public Node () - { - SendCreate (); + protected Node (string tagName) + : base (tagName) + { } public Node AppendChild (Node newChild) diff --git a/Ooui/TextNode.cs b/Ooui/TextNode.cs index 9954790..47441c6 100644 --- a/Ooui/TextNode.cs +++ b/Ooui/TextNode.cs @@ -11,10 +11,12 @@ namespace Ooui } public TextNode () + : base ("#text") { } public TextNode (string text) + : this () { Text = text; } diff --git a/Tests/ButtonTests.cs b/Tests/ButtonTests.cs index 00cf2cf..c1e7f75 100644 --- a/Tests/ButtonTests.cs +++ b/Tests/ButtonTests.cs @@ -12,6 +12,7 @@ namespace Tests public void DefaultCtor () { var b = new Button (); + Assert.AreEqual ("button", b.TagName); Assert.AreEqual ("", b.Text); }