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; }
public XmlNode(IYogaParser parser, XElement element) { this.Xml = element; this.parser = parser; this.Name = this.Xml.Name.LocalName; this.Properties = this.Xml.Attributes().ToDictionary(x => x.Name.LocalName, x => (object)x.Value); this.Children = this.Xml.Elements().Select(x => new XmlNode(parser, x)); }
public JsonNode(IYogaParser parser, JObject element) { this.Json = element; this.parser = parser; this.Name = this.Json[TypePropertyName].Value <string>(); this.Properties = this.Json.Properties() .Where(x => x.Name != TypePropertyName && x.Name != ChildrenPropertyName) .ToDictionary(x => x.Name, GetPropertyValue); var children = ((JArray)this.Json[ChildrenPropertyName]); this.Children = children?.Select(x => new JsonNode(this.parser, (JObject)x)) ?? (IEnumerable <INode>) new INode[0]; }
public static YogaNode Parse(this IYogaParser parser, string xml) { using (var stream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(xml); writer.Flush(); stream.Position = 0; return(parser.Read(stream)); } } }
public NodeRenderer(IYogaParser parser, string name = null) { this.parser = parser; if (name == null) { var typename = typeof(T).Name; if (typename.StartsWith("I", StringComparison.Ordinal)) { typename = typename.Substring(1); } name = typename; } this.Type = typeof(T); this.Name = name; }
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 YogaNodeRenderer(IYogaParser parser) : base(parser) { this.RegisterAllTypePropertyRenderers(); this.RegisterPropertyRenderer(new MarginPropertyRenderer(nameof(YogaNode.Margin), UpdateMargin)); this.RegisterPropertyRenderer(new MarginPropertyRenderer(nameof(YogaNode.Padding), UpdatePadding)); }
public LayoutView(IYogaParser parser) { this.parser = parser; this.parser.RegisterConverter(ColorConverters.FromString()); }
public static void RegisterRelayConverter <TSource, TDestination>(this IYogaParser parser, Func <TSource, (bool, TDestination)> conversion)
public static void RegisterEnumConverter <TEnum>(this IYogaParser parser) { parser.RegisterRelayConverter <string, TEnum>(EnumConverters <TEnum> .FromString); parser.RegisterRelayConverter <int, TEnum>(EnumConverters <TEnum> .FromInt); }
public static void RegisterCastConverter <TSource, TDestination>(this IYogaParser parser) { parser.RegisterConverter(BaseConverters.FromCast <TSource, TDestination>()); }
public ViewRenderer(IYogaParser parser) : base(parser) { this.RegisterAllTypePropertyRenderers(nameof(IView.Frame)); }
public static T ConvertValue <T>(this IYogaParser parser, object value) => (T)parser.ConvertValue(value, typeof(T));