From: chungryeol lim Date: Mon, 26 Dec 2016 09:50:44 +0000 (+0900) Subject: implement ExpressionSearch for RelativeLayout.FromExpression X-Git-Tag: accepted/tizen/4.0/unified/20170816.011313~208 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46a592e93f0ed0f6d17f2ddeb35c96f994692159;p=platform%2Fupstream%2Fxamarin-forms.git implement ExpressionSearch for RelativeLayout.FromExpression Change-Id: Id2fdeea22736d08844d8552015dbb895ae2fa28a Signed-off-by: chungryeol lim --- diff --git a/Xamarin.Forms.Platform.Tizen/Forms.cs b/Xamarin.Forms.Platform.Tizen/Forms.cs index 6aa0e62..f5989e0 100644 --- a/Xamarin.Forms.Platform.Tizen/Forms.cs +++ b/Xamarin.Forms.Platform.Tizen/Forms.cs @@ -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 _results; + Type _targetType; + + public List FindObjects(Expression expression) where T : class + { + _results = new List(); + _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