File tree 3 files changed +26
-5
lines changed
GongSolutions.WPF.DragDrop/Utilities
3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 4
4
using System . Linq ;
5
5
using System . Collections ;
6
6
using System . Collections . ObjectModel ;
7
+ using JetBrains . Annotations ;
7
8
8
9
namespace GongSolutions . Wpf . DragDrop . Utilities
9
10
{
@@ -86,11 +87,24 @@ public static IList TryGetList(this IEnumerable enumerable)
86
87
/// </summary>
87
88
/// <param name="collection">The collection to test.</param>
88
89
/// <returns>True if the collection is a ObservableCollection<></returns>
89
- public static bool IsObservableCollection ( this IList collection )
90
+ public static bool IsObservableCollection ( [ CanBeNull ] this IList collection )
90
91
{
91
- return collection != null
92
- && collection . GetType ( ) . IsGenericType
93
- && collection . GetType ( ) . GetGenericTypeDefinition ( ) == typeof ( ObservableCollection < > ) ;
92
+ return collection != null && IsObservableCollectionType ( collection . GetType ( ) ) ;
93
+ }
94
+
95
+ private static bool IsObservableCollectionType ( [ CanBeNull ] Type type )
96
+ {
97
+ if ( type is null || ! typeof ( IList ) . IsAssignableFrom ( type ) )
98
+ {
99
+ return false ;
100
+ }
101
+
102
+ if ( type . IsGenericType && type . GetGenericTypeDefinition ( ) == typeof ( ObservableCollection < > ) )
103
+ {
104
+ return true ;
105
+ }
106
+
107
+ return IsObservableCollectionType ( type . BaseType ) ;
94
108
}
95
109
96
110
/// <summary>
Original file line number Diff line number Diff line change @@ -158,6 +158,10 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
158
158
}
159
159
}
160
160
161
+ public class ItemModelObservableCollection : ObservableCollection < ItemModel >
162
+ {
163
+ }
164
+
161
165
[ Serializable ]
162
166
public class SerializableItemModel
163
167
{
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public SampleData()
17
17
this . ClonableCollection1 . Add ( new ClonableItemModel ( n + 1 ) ) ;
18
18
this . DataGridCollection1 . Add ( new DataGridRowModel ( ) ) ;
19
19
}
20
+
20
21
for ( var n = 0 ; n < 10 ; ++ n )
21
22
{
22
23
this . Collection4 . Add ( new ItemModel ( ) { Caption = $ "Model { n + 1 } " } ) ;
@@ -40,6 +41,7 @@ public SampleData()
40
41
{
41
42
root . Children . Add ( new TreeNode ( $ "Item { i + 10 * r } ") ) ;
42
43
}
44
+
43
45
this . TreeCollection1 . Add ( root ) ;
44
46
if ( r == 2 )
45
47
{
@@ -51,6 +53,7 @@ public SampleData()
51
53
{
52
54
this . TabItemCollection1 . Add ( new TabItemModel ( i + 1 ) ) ;
53
55
}
56
+
54
57
this . TabItemCollection2 . Add ( new TabItemModel ( 1 ) ) ;
55
58
}
56
59
@@ -62,7 +65,7 @@ public SampleData()
62
65
63
66
public SerializableDropHandler SerializableDropHandler { get ; set ; } = new SerializableDropHandler ( ) ;
64
67
65
- public ObservableCollection < ItemModel > Collection1 { get ; set ; } = new ObservableCollection < ItemModel > ( ) ;
68
+ public ItemModelObservableCollection Collection1 { get ; set ; } = new ItemModelObservableCollection ( ) ;
66
69
67
70
public ObservableCollection < ItemModel > Collection2 { get ; set ; } = new ObservableCollection < ItemModel > ( ) ;
68
71
You can’t perform that action at this time.
0 commit comments