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;
        }
Esempio n. 2
0
 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];
        }
Esempio n. 4
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));
         }
     }
 }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
        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));
 }
Esempio n. 8
0
 public LayoutView(IYogaParser parser)
 {
     this.parser = parser;
     this.parser.RegisterConverter(ColorConverters.FromString());
 }
Esempio n. 9
0
 public static void RegisterRelayConverter <TSource, TDestination>(this IYogaParser parser, Func <TSource, (bool, TDestination)> conversion)
Esempio n. 10
0
 public static void RegisterEnumConverter <TEnum>(this IYogaParser parser)
 {
     parser.RegisterRelayConverter <string, TEnum>(EnumConverters <TEnum> .FromString);
     parser.RegisterRelayConverter <int, TEnum>(EnumConverters <TEnum> .FromInt);
 }
Esempio n. 11
0
 public static void RegisterCastConverter <TSource, TDestination>(this IYogaParser parser)
 {
     parser.RegisterConverter(BaseConverters.FromCast <TSource, TDestination>());
 }
Esempio n. 12
0
 public ViewRenderer(IYogaParser parser) : base(parser)
 {
     this.RegisterAllTypePropertyRenderers(nameof(IView.Frame));
 }
Esempio n. 13
0
 public static T ConvertValue <T>(this IYogaParser parser, object value) => (T)parser.ConvertValue(value, typeof(T));