Browse Source

Fix MemberSelector.

Steven Kirk 9 years ago
parent
commit
0b0ca8b0cb

+ 9 - 36
src/Markup/Avalonia.Markup.Xaml/Templates/MemberSelector.cs

@@ -5,14 +5,13 @@ using Avalonia.Controls.Templates;
 using Avalonia.Data;
 using Avalonia.Markup.Data;
 using System;
+using System.Reactive.Linq;
 
 namespace Avalonia.Markup.Xaml.Templates
 {
     public class MemberSelector : IMemberSelector
     {
-        private ExpressionNode _expressionNode;
         private string _memberName;
-        private ExpressionNode _memberValueNode;
 
         public string MemberName
         {
@@ -22,48 +21,22 @@ namespace Avalonia.Markup.Xaml.Templates
                 if (_memberName != value)
                 {
                     _memberName = value;
-                    _expressionNode = null;
-                    _memberValueNode = null;
                 }
             }
         }
 
         public object Select(object o)
         {
-            throw new NotImplementedException();
-            ////if (string.IsNullOrEmpty(MemberName))
-            ////{
-            ////    return o;
-            ////}
-
-            ////if (_expressionNode == null)
-            ////{
-            ////    _expressionNode = ExpressionNodeBuilder.Build(MemberName);
-
-            ////    _memberValueNode = _expressionNode;
-
-            ////    while (_memberValueNode.Next != null)
-            ////    {
-            ////        _memberValueNode = _memberValueNode.Next;
-            ////    }
-            ////}
-
-            ////_expressionNode.Target = new WeakReference(o);
-
-            ////object result = _memberValueNode.CurrentValue.Target;
-
-            ////_expressionNode.Target = null;
+            if (string.IsNullOrEmpty(MemberName))
+            {
+                return o;
+            }
 
-            ////if (result == AvaloniaProperty.UnsetValue)
-            ////{
-            ////    return null;
-            ////}
-            ////else if (result is BindingNotification)
-            ////{
-            ////    return null;
-            ////}
+            var expression = new ExpressionObserver(o, MemberName);
+            object result = AvaloniaProperty.UnsetValue;
 
-            ////return result;
+            expression.Subscribe(x => result = x);
+            return (result == AvaloniaProperty.UnsetValue || result is BindingNotification) ? null : result;
         }
     }
 }

+ 0 - 1
src/Markup/Avalonia.Markup/Properties/AssemblyInfo.cs

@@ -8,4 +8,3 @@ using System.Runtime.CompilerServices;
 [assembly: AssemblyTitle("Avalonia.Markup")]
 [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Markup")]
 [assembly: InternalsVisibleTo("Avalonia.Markup.UnitTests")]
-[assembly: InternalsVisibleTo("Avalonia.Markup.Xaml")]