implement ExpressionSearch for RelativeLayout.FromExpression
authorchungryeol lim <cdark.lim@samsung.com>
Mon, 26 Dec 2016 09:50:44 +0000 (18:50 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Mon, 24 Apr 2017 04:36:44 +0000 (13:36 +0900)
Change-Id: Id2fdeea22736d08844d8552015dbb895ae2fa28a
Signed-off-by: chungryeol lim <cdark.lim@samsung.com>
Xamarin.Forms.Platform.Tizen/Forms.cs

index 6aa0e62..f5989e0 100644 (file)
@@ -1,7 +1,10 @@
 using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
 using System.Reflection;
-using Tizen.Applications;
 using ElmSharp;
+using Tizen.Applications;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -155,7 +158,7 @@ namespace Xamarin.Forms.Platform.Tizen
 
                        // FIXME: We should consider TV and Common (Desktop) profiles also.
                        Device.Idiom = TargetIdiom.Phone;
-
+                       ExpressionSearch.Default = new TizenExpressionSearch();
                        IsInitialized = true;
                }
 
@@ -170,4 +173,31 @@ namespace Xamarin.Forms.Platform.Tizen
                        return Color.Black;
                }
        }
-}
+
+       class TizenExpressionSearch : ExpressionVisitor, IExpressionSearch
+       {
+               List<object> _results;
+               Type _targetType;
+
+               public List<T> FindObjects<T>(Expression expression) where T : class
+               {
+                       _results = new List<object>();
+                       _targetType = typeof(T);
+                       Visit(expression);
+                       return _results.Select(o => o as T).ToList();
+               }
+
+               protected override Expression VisitMember(MemberExpression node)
+               {
+                       if (node.Expression is ConstantExpression && node.Member is FieldInfo)
+                       {
+                               var container = ((ConstantExpression)node.Expression).Value;
+                               var value = ((FieldInfo)node.Member).GetValue(container);
+
+                               if (_targetType.IsInstanceOfType(value))
+                                       _results.Add(value);
+                       }
+                       return base.VisitMember(node);
+               }
+       }
+}
\ No newline at end of file