Browse Source

For Perf. Reasons don't use Exception

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

23
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)
{ {
collectionType.InvokeMember( var mth = collectionType.GetMethod("Insert", BindingFlags.Public | BindingFlags.Instance,
"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null);
null, collectionInstance,
new object[] { index, newElement.GetValueFor(null) }, if (mth != null) {
CultureInfo.InvariantCulture); collectionType.InvokeMember(
"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, collectionInstance,
new object[] { index, newElement.GetValueFor(null) },
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