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 }); }
public virtual void AddToDictionary(object instance, object key, object item) { if (instance == null) { throw new ArgumentNullException("instance"); } IDictionary dictionary = instance as IDictionary; if (dictionary != null) { dictionary.Add(key, item); } else { XamlType xamlType; this.ThrowIfUnknown(); if (!this._xamlType.IsDictionary) { throw new NotSupportedException(System.Xaml.SR.Get("OnlySupportedOnDictionaries")); } if (item != null) { xamlType = this._xamlType.SchemaContext.GetXamlType(item.GetType()); } else { xamlType = this._xamlType.ItemType; } MethodInfo addMethod = this.GetAddMethod(xamlType); if (addMethod == null) { throw new XamlSchemaException(System.Xaml.SR.Get("NoAddMethodFound", new object[] { this._xamlType, xamlType })); } SafeReflectionInvoker.InvokeMethod(addMethod, instance, new object[] { key, item }); } }
public virtual void AddToCollection(object instance, object item) { if (instance == null) { throw new ArgumentNullException("instance"); } IList list = instance as IList; if (list != null) { list.Add(item); } else { XamlType xamlType; this.ThrowIfUnknown(); if (!this._xamlType.IsCollection) { throw new NotSupportedException(System.Xaml.SR.Get("OnlySupportedOnCollections")); } if (item != null) { xamlType = this._xamlType.SchemaContext.GetXamlType(item.GetType()); } else { xamlType = this._xamlType.ItemType; } MethodInfo addMethod = this.GetAddMethod(xamlType); if (addMethod == null) { throw new XamlSchemaException(System.Xaml.SR.Get("NoAddMethodFound", new object[] { this._xamlType, xamlType })); } SafeReflectionInvoker.InvokeMethod(addMethod, instance, new object[] { item }); } }
private object CreateInstanceWithActivator(Type type, object[] arguments) { return(SafeReflectionInvoker.CreateInstance(type, arguments)); }