@@ -79,12 +79,10 @@ public TProperty GetPropertyAs<TProperty, TValueType>(IBindingContext context, M
79
79
80
80
if ( _wrappersByConverter . TryGetValue ( converterId , out var propertyWrappers ) )
81
81
{
82
- if ( propertyWrappers . Count > 0 )
82
+ var validPropertyWrapper = GetValidPropertyWrapper < TValueType > ( propertyWrappers , property ) ;
83
+ if ( validPropertyWrapper != null )
83
84
{
84
- return ( TProperty ) propertyWrappers
85
- . Dequeue ( )
86
- . AsPropertyWrapper ( )
87
- . SetProperty ( property ) ;
85
+ return ( TProperty ) validPropertyWrapper . SetProperty ( property ) ;
88
86
}
89
87
}
90
88
else
@@ -117,12 +115,10 @@ public TProperty GetProperty<TProperty, TValueType>(IBindingContext context, Bin
117
115
118
116
if ( _wrappersByConverter . TryGetValue ( converterId , out var propertyWrappers ) )
119
117
{
120
- if ( propertyWrappers . Count > 0 )
118
+ var validPropertyWrapper = GetValidPropertyWrapper < TValueType > ( propertyWrappers , property ) ;
119
+ if ( validPropertyWrapper != null )
121
120
{
122
- return ( TProperty ) propertyWrappers
123
- . Dequeue ( )
124
- . AsPropertyWrapper ( )
125
- . SetProperty ( property ) ;
121
+ return ( TProperty ) validPropertyWrapper . SetProperty ( property ) ;
126
122
}
127
123
}
128
124
else
@@ -144,6 +140,28 @@ public TProperty GetProperty<TProperty, TValueType>(IBindingContext context, Bin
144
140
145
141
return ( TProperty ) ObjectWrapperHelper . CreatePropertyWrapper ( wrapperType , args , converterId , property ) ;
146
142
}
143
+
144
+ private static IPropertyWrapper GetValidPropertyWrapper < TValueType > ( Queue < IObjectWrapper > propertyWrappers , IBaseProperty property )
145
+ {
146
+ for ( var i = 0 ; i < propertyWrappers . Count ; ++ i )
147
+ {
148
+ var propertyWrapper = propertyWrappers . Dequeue ( ) . AsPropertyWrapper ( ) ;
149
+
150
+ if ( IsValidPropertyWrapper < TValueType > ( propertyWrapper , property ) )
151
+ {
152
+ return propertyWrapper ;
153
+ }
154
+
155
+ propertyWrappers . Enqueue ( propertyWrapper ) ;
156
+ }
157
+
158
+ return null ;
159
+ }
160
+
161
+ private static bool IsValidPropertyWrapper < TValueType > ( IPropertyWrapper propertyWrapper , IBaseProperty property )
162
+ {
163
+ return property is IProperty == propertyWrapper is IProperty < TValueType > ; //either both implement IProperty, or both ain't
164
+ }
147
165
148
166
public TCommand GetCommand < TCommand > ( IBindingContext context , MemberInfo memberInfo )
149
167
where TCommand : IBaseCommand
0 commit comments