Remove Mapping class

This commit is contained in:
Frank A. Krueger 2017-06-14 23:20:51 -07:00
parent 76b9d95ddf
commit 592b7e4bc2
9 changed files with 27 additions and 43 deletions

View File

@ -22,10 +22,12 @@ namespace Ooui
}
public Button ()
: base ("button")
{
}
public Button (string text)
: this ()
{
Text = text;
}

View File

@ -4,5 +4,9 @@ namespace Ooui
{
public class Div : Element
{
public Div ()
: base ("div")
{
}
}
}

View File

@ -4,6 +4,11 @@ namespace Ooui
{
public abstract class Element : Node
{
protected Element (string tagName)
: base (tagName)
{
}
string className = "";
public string ClassName {
get => className;

View File

@ -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<Message> MessageSent;
public IEnumerable<Message> 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,
});
}

View File

@ -9,5 +9,10 @@ namespace Ooui
get => name;
set => SetProperty (ref name, value, "name");
}
public FormControl (string tagName)
: base (tagName)
{
}
}
}

View File

@ -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<string, Mapping> mappings =
new Dictionary<string, Mapping> ();
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;
}
}
}

View File

@ -20,9 +20,9 @@ namespace Ooui
}
}
public Node ()
protected Node (string tagName)
: base (tagName)
{
SendCreate ();
}
public Node AppendChild (Node newChild)

View File

@ -11,10 +11,12 @@ namespace Ooui
}
public TextNode ()
: base ("#text")
{
}
public TextNode (string text)
: this ()
{
Text = text;
}

View File

@ -12,6 +12,7 @@ namespace Tests
public void DefaultCtor ()
{
var b = new Button ();
Assert.AreEqual ("button", b.TagName);
Assert.AreEqual ("", b.Text);
}