Browse Source

Last fix was not correct -> We don't know the Type of the Insert Object

pull/633/head
jkuehner 11 years ago
parent
commit
47a67fe2d7
  1. 22
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

22
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -21,6 +21,7 @@ using System.Diagnostics;
using System.Collections; using System.Collections;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Windows; using System.Windows;
using System.Windows.Documents; using System.Windows.Documents;
@ -39,7 +40,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
public static bool IsCollectionType(Type type) public static bool IsCollectionType(Type type)
{ {
return type != typeof(LineBreak) && ( return type != typeof(LineBreak) && (
typeof(IList).IsAssignableFrom(type) typeof(IList).IsAssignableFrom(type)
|| type.IsArray || type.IsArray
|| typeof(IAddChild).IsAssignableFrom(type) || typeof(IAddChild).IsAssignableFrom(type)
|| typeof(IDictionary).IsAssignableFrom(type)); || typeof(IDictionary).IsAssignableFrom(type));
@ -85,12 +86,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else if (collectionInstance is IDictionary) { } else if (collectionInstance is IDictionary) {
object val = newElement.GetValueFor(null); object val = newElement.GetValueFor(null);
object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null; object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
if (key == null || key == "") if (key == null || key == "")
{ {
if (val is Style) if (val is Style)
key = ((Style)val).TargetType; key = ((Style)val).TargetType;
} }
if (key == null || (key as string) == "") if (key == null || (key as string) == "")
key = val; key = val;
((IDictionary)collectionInstance).Add(key, val); ((IDictionary)collectionInstance).Add(key, val);
} else { } else {
@ -102,15 +103,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
/// <summary> /// <summary>
/// Adds a value at the specified index in the collection. /// Adds a value at the specified index in the collection.
/// </summary> /// </summary>
public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
{ {
var mth = collectionType.GetMethod("Insert", BindingFlags.Public | BindingFlags.Instance, var hasInsert = collectionType.GetMethods().Any(x => x.Name == "Insert");
null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null);
if (mth != null) { if (hasInsert) {
collectionType.InvokeMember( collectionType.InvokeMember(
"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, "Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, collectionInstance, null, collectionInstance,

Loading…
Cancel
Save