private void SetValueSafeCritical(object instance, object value) { if (UnderlyingSetter.IsStatic) { SafeReflectionInvoker.InvokeMethod(UnderlyingSetter, null, new object[] { instance, value }); } else { SafeReflectionInvoker.InvokeMethod(UnderlyingSetter, instance, new object[] { value }); } }
private object GetValueSafeCritical(object instance) { if (UnderlyingGetter.IsStatic) { return(SafeReflectionInvoker.InvokeMethod(UnderlyingGetter, null, new object[] { instance })); } else { return(SafeReflectionInvoker.InvokeMethod(UnderlyingGetter, instance, s_emptyObjectArray)); } }
public virtual IEnumerator GetItems(object instance) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } IEnumerable enumerable = instance as IEnumerable; if (enumerable != null) { return(enumerable.GetEnumerator()); } ThrowIfUnknown(); if (!_xamlType.IsCollection && !_xamlType.IsDictionary) { throw new NotSupportedException(SR.Get(SRID.OnlySupportedOnCollectionsAndDictionaries)); } MethodInfo getEnumMethod = GetEnumeratorMethod(); return((IEnumerator)SafeReflectionInvoker.InvokeMethod(getEnumMethod, instance, s_emptyObjectArray)); }
public virtual void AddToCollection(object instance, object item) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } IList list = instance as IList; if (list != null) { list.Add(item); return; } ThrowIfUnknown(); if (!_xamlType.IsCollection) { throw new NotSupportedException(SR.Get(SRID.OnlySupportedOnCollections)); } XamlType itemType; if (item != null) { itemType = _xamlType.SchemaContext.GetXamlType(item.GetType()); } else { itemType = _xamlType.ItemType; } MethodInfo addMethod = GetAddMethod(itemType); if (addMethod == null) { throw new XamlSchemaException(SR.Get(SRID.NoAddMethodFound, _xamlType, itemType)); } SafeReflectionInvoker.InvokeMethod(addMethod, instance, new object[] { item }); }
public virtual void AddToDictionary(object instance, object key, object item) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } IDictionary dictionary = instance as IDictionary; if (dictionary != null) { dictionary.Add(key, item); return; } ThrowIfUnknown(); if (!_xamlType.IsDictionary) { throw new NotSupportedException(SR.Get(SRID.OnlySupportedOnDictionaries)); } XamlType itemType; if (item != null) { itemType = _xamlType.SchemaContext.GetXamlType(item.GetType()); } else { itemType = _xamlType.ItemType; } MethodInfo addMethod = GetAddMethod(itemType); if (addMethod == null) { throw new XamlSchemaException(SR.Get(SRID.NoAddMethodFound, _xamlType, itemType)); } SafeReflectionInvoker.InvokeMethod(addMethod, instance, new object[] { key, item }); }