Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4585cd

Browse files
committed
Added validation check for access type (Normal/ReadOnly)
1 parent b94d487 commit d4585cd

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

‎src/UnityMvvmToolkit.Core/Internal/ObjectHandlers/ObjectWrapperHandler.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@ public TProperty GetPropertyAs<TProperty, TValueType>(IBindingContext context, M
7979

8080
if (_wrappersByConverter.TryGetValue(converterId, out var propertyWrappers))
8181
{
82-
if (propertyWrappers.Count > 0)
82+
var validPropertyWrapper = GetValidPropertyWrapper<TValueType>(propertyWrappers, property);
83+
if (validPropertyWrapper != null)
8384
{
84-
return (TProperty) propertyWrappers
85-
.Dequeue()
86-
.AsPropertyWrapper()
87-
.SetProperty(property);
85+
return (TProperty)validPropertyWrapper.SetProperty(property);
8886
}
8987
}
9088
else
@@ -117,12 +115,10 @@ public TProperty GetProperty<TProperty, TValueType>(IBindingContext context, Bin
117115

118116
if (_wrappersByConverter.TryGetValue(converterId, out var propertyWrappers))
119117
{
120-
if (propertyWrappers.Count > 0)
118+
var validPropertyWrapper = GetValidPropertyWrapper<TValueType>(propertyWrappers, property);
119+
if (validPropertyWrapper != null)
121120
{
122-
return (TProperty) propertyWrappers
123-
.Dequeue()
124-
.AsPropertyWrapper()
125-
.SetProperty(property);
121+
return (TProperty)validPropertyWrapper.SetProperty(property);
126122
}
127123
}
128124
else
@@ -144,6 +140,28 @@ public TProperty GetProperty<TProperty, TValueType>(IBindingContext context, Bin
144140

145141
return (TProperty) ObjectWrapperHelper.CreatePropertyWrapper(wrapperType, args, converterId, property);
146142
}
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+
}
147165

148166
public TCommand GetCommand<TCommand>(IBindingContext context, MemberInfo memberInfo)
149167
where TCommand : IBaseCommand

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /