Browse Source

For Perf. Reasons don't use Exception

pull/633/head
jkuehner 11 years ago
parent
commit
2ede4f4105
  1. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

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

@ -105,13 +105,22 @@ 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 void 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,
null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null);
if (mth != null) {
collectionType.InvokeMember( collectionType.InvokeMember(
"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, "Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, collectionInstance, null, collectionInstance,
new object[] { index, newElement.GetValueFor(null) }, new object[] { index, newElement.GetValueFor(null) },
CultureInfo.InvariantCulture); CultureInfo.InvariantCulture);
return true;
}
return false;
} }
/// <summary> /// <summary>
@ -121,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal static bool TryInsert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) internal static bool TryInsert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
{ {
try { try {
Insert(collectionType, collectionInstance, newElement, index); return Insert(collectionType, collectionInstance, newElement, index);
} catch (MissingMethodException) { } catch (MissingMethodException) {
return false; return false;
} }

Loading…
Cancel
Save