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 3fda705

Browse files
Merge pull request #40 from LibraStack/develop
Add BindableListView<TItem, TCollection>
2 parents c1cb62d + 42bc5f8 commit 3fda705

26 files changed

+307
-231
lines changed

‎src/UnityMvvmToolkit.Core/BindingContextObjectProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public void Dispose()
157157

158158
[MethodImpl(MethodImplOptions.AggressiveInlining)]
159159
private TProperty GetProperty<TProperty, TValueType>(IBindingContext context, BindingData bindingData)
160+
where TProperty : IBaseProperty
160161
{
161162
if (TryGetContextMemberInfo(context.GetType(), bindingData.PropertyName, out var memberInfo) == false)
162163
{

‎src/UnityMvvmToolkit.Core/Internal/Helpers/ObjectWrapperHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using System;
22
using System.Runtime.CompilerServices;
3+
using UnityMvvmToolkit.Core.Interfaces;
34
using UnityMvvmToolkit.Core.Internal.Interfaces;
45

56
namespace UnityMvvmToolkit.Core.Internal.Helpers
67
{
78
internal static class ObjectWrapperHelper
89
{
910
[MethodImpl(MethodImplOptions.AggressiveInlining)]
10-
public static IPropertyWrapper CreatePropertyWrapper(Type type, object[] args, int converterId, object property)
11+
public static IPropertyWrapper CreatePropertyWrapper(Type type, object[] args, int converterId,
12+
IBaseProperty property)
1113
{
1214
var propertyWrapper = (IPropertyWrapper) Activator.CreateInstance(type, args);
1315

@@ -17,7 +19,8 @@ public static IPropertyWrapper CreatePropertyWrapper(Type type, object[] args, i
1719
}
1820

1921
[MethodImpl(MethodImplOptions.AggressiveInlining)]
20-
public static ICommandWrapper CreateCommandWrapper(Type type, object[] args, int converterId, int commandId, object command)
22+
public static ICommandWrapper CreateCommandWrapper(Type type, object[] args, int converterId, int commandId,
23+
IBaseCommand command)
2124
{
2225
var commandWrapper = (ICommandWrapper) Activator.CreateInstance(type, args);
2326

‎src/UnityMvvmToolkit.Core/Internal/Interfaces/ICommandWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ internal interface ICommandWrapper : IObjectWrapper<ICommandWrapper>, IBaseComma
66
{
77
int CommandId { get; }
88

9-
ICommandWrapper SetCommand(int commandId, object command);
9+
ICommandWrapper SetCommand(int commandId, IBaseCommand command);
1010

1111
ICommandWrapper RegisterParameter(int elementId, string parameter);
1212
int UnregisterParameter(int elementId);
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
namespace UnityMvvmToolkit.Core.Internal.Interfaces
1+
using UnityMvvmToolkit.Core.Interfaces;
2+
3+
namespace UnityMvvmToolkit.Core.Internal.Interfaces
24
{
35
internal interface IPropertyWrapper : IObjectWrapper<IPropertyWrapper>
46
{
5-
IPropertyWrapper SetProperty(object property);
7+
IPropertyWrapper SetProperty(IBaseProperty property);
68
}
79
}

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public void CreateValueConverterInstances<T>(int capacity, WarmupType warmupType
5151
}
5252

5353
public TProperty GetProperty<TProperty, TValueType>(IBindingContext context, BindingData bindingData,
54-
MemberInfo memberInfo)
54+
MemberInfo memberInfo)whereTProperty:IBaseProperty
5555
{
56-
var property = GetMemberValue(context, memberInfo, out var propertyType);
56+
var property = GetMemberValue<IBaseProperty>(context, memberInfo, out var propertyType);
5757

5858
var targetType = typeof(TValueType);
5959
var sourceType = propertyType.GenericTypeArguments[0];
@@ -97,22 +97,15 @@ public TProperty GetProperty<TProperty, TValueType>(IBindingContext context, Bin
9797
}
9898

9999
public TCommand GetCommand<TCommand>(IBindingContext context, MemberInfo memberInfo)
100+
where TCommand : IBaseCommand
100101
{
101-
var command = GetMemberValue(context, memberInfo, out var commandType);
102-
103-
if (typeof(TCommand).IsAssignableFrom(commandType))
104-
{
105-
return (TCommand) command;
106-
}
107-
108-
throw new InvalidCastException(
109-
$"Can not cast the '{commandType}' command to the '{typeof(TCommand)}' command.");
102+
return GetMemberValue<TCommand>(context, memberInfo, out _);
110103
}
111104

112105
public ICommandWrapper GetCommandWrapper(IBindingContext context, CommandBindingData bindingData,
113106
MemberInfo memberInfo)
114107
{
115-
var command = GetMemberValue(context, memberInfo, out var commandType);
108+
var command = GetMemberValue<IBaseCommand>(context, memberInfo, out var commandType);
116109

117110
if (commandType.IsGenericType == false ||
118111
commandType.GetInterface(nameof(IBaseCommand)) == null)
@@ -312,7 +305,7 @@ private void ReturnWrapper(IObjectWrapper wrapper)
312305
}
313306

314307
[MethodImpl(MethodImplOptions.AggressiveInlining)]
315-
private static object GetMemberValue(IBindingContext context, MemberInfo memberInfo, out Type memberType)
308+
private static T GetMemberValue<T>(IBindingContext context, MemberInfo memberInfo, out Type memberType)
316309
{
317310
switch (memberInfo.MemberType)
318311
{
@@ -321,15 +314,15 @@ private static object GetMemberValue(IBindingContext context, MemberInfo memberI
321314
var fieldInfo = (FieldInfo) memberInfo;
322315
memberType = fieldInfo.FieldType;
323316

324-
return fieldInfo.GetValue(context);
317+
return (T)fieldInfo.GetValue(context);
325318
}
326319

327320
case MemberTypes.Property:
328321
{
329322
var propertyInfo = (PropertyInfo) memberInfo;
330323
memberType = propertyInfo.PropertyType;
331324

332-
return propertyInfo.GetValue(context);
325+
return (T)propertyInfo.GetValue(context);
333326
}
334327

335328
default:

‎src/UnityMvvmToolkit.Core/Internal/ObjectWrappers/CommandWrapper.TValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public ICommandWrapper SetConverterId(int converterId)
4343
return this;
4444
}
4545

46-
public ICommandWrapper SetCommand(int commandId, object command)
46+
public ICommandWrapper SetCommand(int commandId, IBaseCommand command)
4747
{
48-
if (_command != null)
48+
if (_command is not null)
4949
{
5050
throw new InvalidOperationException(
5151
$"{nameof(CommandWrapper<TValue>)} was not reset.");

‎src/UnityMvvmToolkit.Core/Internal/ObjectWrappers/PropertyWrapper.TSource.TValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public IPropertyWrapper SetConverterId(int converterId)
4848
return this;
4949
}
5050

51-
public IPropertyWrapper SetProperty(object property)
51+
public IPropertyWrapper SetProperty(IBaseProperty property)
5252
{
53-
if (_property != null)
53+
if (_property is not null)
5454
{
5555
throw new InvalidOperationException(
5656
$"{nameof(PropertyWrapper<TValue, TSource>)} was not reset.");

‎src/UnityMvvmToolkit.Core/Internal/ObjectWrappers/ReadOnlyPropertyWrapper.TSource.TValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public IPropertyWrapper SetConverterId(int converterId)
4646
return this;
4747
}
4848

49-
public IPropertyWrapper SetProperty(object readOnlyProperty)
49+
public IPropertyWrapper SetProperty(IBaseProperty readOnlyProperty)
5050
{
5151
if (_isInitialized)
5252
{

‎src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Core/BindingContextObjectProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public void Dispose()
157157

158158
[MethodImpl(MethodImplOptions.AggressiveInlining)]
159159
private TProperty GetProperty<TProperty, TValueType>(IBindingContext context, BindingData bindingData)
160+
where TProperty : IBaseProperty
160161
{
161162
if (TryGetContextMemberInfo(context.GetType(), bindingData.PropertyName, out var memberInfo) == false)
162163
{

‎src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Core/Internal/Helpers/ObjectWrapperHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using System;
22
using System.Runtime.CompilerServices;
3+
using UnityMvvmToolkit.Core.Interfaces;
34
using UnityMvvmToolkit.Core.Internal.Interfaces;
45

56
namespace UnityMvvmToolkit.Core.Internal.Helpers
67
{
78
internal static class ObjectWrapperHelper
89
{
910
[MethodImpl(MethodImplOptions.AggressiveInlining)]
10-
public static IPropertyWrapper CreatePropertyWrapper(Type type, object[] args, int converterId, object property)
11+
public static IPropertyWrapper CreatePropertyWrapper(Type type, object[] args, int converterId,
12+
IBaseProperty property)
1113
{
1214
var propertyWrapper = (IPropertyWrapper) Activator.CreateInstance(type, args);
1315

@@ -17,7 +19,8 @@ public static IPropertyWrapper CreatePropertyWrapper(Type type, object[] args, i
1719
}
1820

1921
[MethodImpl(MethodImplOptions.AggressiveInlining)]
20-
public static ICommandWrapper CreateCommandWrapper(Type type, object[] args, int converterId, int commandId, object command)
22+
public static ICommandWrapper CreateCommandWrapper(Type type, object[] args, int converterId, int commandId,
23+
IBaseCommand command)
2124
{
2225
var commandWrapper = (ICommandWrapper) Activator.CreateInstance(type, args);
2326

0 commit comments

Comments
(0)

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