public JsonNode(IYogaParser parser, INode node) { this.Name = node.Name; this.Properties = new Dictionary <string, object>(node.Properties); this.Json = new JObject(); this.Json[TypePropertyName] = this.Name; foreach (var prop in this.Properties) { var value = parser.ConvertValue(prop.Value, typeof(bool), typeof(int), typeof(float), typeof(string)); this.Json[prop.Key] = JToken.FromObject(value); } var children = new List <INode>(); var jarray = new JArray(); foreach (var child in node.Children) { var childNode = new JsonNode(parser, child); children.Add(childNode); jarray.Add(childNode.Json); } this.Children = children.ToArray(); this.Json[ChildrenPropertyName] = jarray; }
protected void RenderProperty(object instance, string name, object value) { var renderer = this.propertyRenderers.FirstOrDefault(x => x.Name == name); if (renderer != null) { var v = parser.ConvertValue(value, renderer.Type); renderer.Render(instance, v); } }
public XmlNode(IYogaParser parser, INode node) { this.Name = node.Name; this.Properties = new Dictionary <string, object>(node.Properties); this.Xml = new XElement(this.Name); foreach (var prop in this.Properties) { var value = parser.ConvertValue <string>(prop.Value); this.Xml.SetAttributeValue(prop.Key, value); } var children = new List <INode>(); foreach (var child in node.Children) { var childNode = new XmlNode(parser, child); children.Add(childNode); this.Xml.Add(childNode.Xml); } this.Children = children.ToArray(); }
public static T ConvertValue <T>(this IYogaParser parser, object value) => (T)parser.ConvertValue(value, typeof(T));