Example #1
0
 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 });
     }
 }
Example #2
0
 private object GetValueSafeCritical(object instance)
 {
     if (UnderlyingGetter.IsStatic)
     {
         return(SafeReflectionInvoker.InvokeMethod(UnderlyingGetter, null, new object[] { instance }));
     }
     else
     {
         return(SafeReflectionInvoker.InvokeMethod(UnderlyingGetter, instance, s_emptyObjectArray));
     }
 }
Example #3
0
        public virtual IEnumerator GetItems(object instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            IEnumerable enumerable = instance as IEnumerable;

            if (enumerable != null)
            {
                return(enumerable.GetEnumerator());
            }
            this.ThrowIfUnknown();
            if (!this._xamlType.IsCollection && !this._xamlType.IsDictionary)
            {
                throw new NotSupportedException(System.Xaml.SR.Get("OnlySupportedOnCollectionsAndDictionaries"));
            }
            return((IEnumerator)SafeReflectionInvoker.InvokeMethod(this.GetEnumeratorMethod(), instance, s_emptyObjectArray));
        }
Example #4
0
        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));
        }
Example #5
0
        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 });
        }
Example #6
0
        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 });
        }
Example #7
0
        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 });
            }
        }
Example #8
0
        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 });
            }
        }