GetValue() public abstract method

public abstract GetValue ( object instance ) : object
instance object
return object
Esempio n. 1
0
        void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
        {
            bool         isDefaultValueSet         = false;
            object       defaultPropertyValue      = null;
            XamlProperty defaultCollectionProperty = null;

            if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty)
            {
                defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
                obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
            }

            foreach (XmlNode childNode in GetNormalizedChildNodes(element))
            {
                XmlElement childElement = childNode as XmlElement;
                if (childElement != null)
                {
                    if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
                    {
                        continue;
                    }

                    if (ObjectChildElementIsPropertyElement(childElement))
                    {
                        ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
                        continue;
                    }
                }
                if (initializeFromTextValueInsteadOfConstructor != null)
                {
                    continue;
                }
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (defaultProperty != null && defaultProperty.IsCollection)
                    {
                        defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
                        CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
                    }
                    else
                    {
                        if (defaultProperty == null)
                        {
                            throw new XamlLoadException("This element does not have a default value, cannot assign to it");
                        }

                        if (isDefaultValueSet)
                        {
                            throw new XamlLoadException("default property may have only one value assigned");
                        }

                        obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
                        isDefaultValueSet = true;
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void InsertItem(int index, XamlPropertyValue item)
        {
            XamlPropertyInfo info       = property.propertyInfo;
            object           collection = info.GetValue(property.ParentObject.Instance);

            CollectionSupport.Insert(info.ReturnType, collection, item, index);

            item.ParentProperty = property;
            property.InsertNodeInCollection(item.GetNodeForCollection(), index);

            base.InsertItem(index, item);
        }
Esempio n. 3
0
        protected override void RemoveItem(int index)
        {
            XamlPropertyInfo info       = property.propertyInfo;
            object           collection = info.GetValue(property.ParentObject.Instance);

            if (!CollectionSupport.RemoveItemAt(info.ReturnType, collection, index))
            {
                CollectionSupport.RemoveItem(info.ReturnType, collection, this[index].GetValueFor(info));
            }

            this[index].RemoveNodeFromParent();
            this[index].ParentProperty = null;
            base.RemoveItem(index);
        }
        protected override void InsertItem(int index, XamlPropertyValue item)
        {
            XamlPropertyInfo info       = property.propertyInfo;
            object           collection = info.GetValue(property.ParentObject.Instance);

            if (!CollectionSupport.TryInsert(info.ReturnType, collection, item, index))
            {
                CollectionSupport.AddToCollection(info.ReturnType, collection, item);
            }

            item.ParentProperty = property;
            property.InsertNodeInCollection(item.GetNodeForCollection(), index);

            base.InsertItem(index, item);

            if (CollectionChanged != null)
            {
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
            }
        }
        protected override void RemoveItem(int index)
        {
            XamlPropertyInfo info       = property.propertyInfo;
            object           collection = info.GetValue(property.ParentObject.Instance);

            if (!CollectionSupport.RemoveItemAt(info.ReturnType, collection, index))
            {
                var propertyValue = this[index];
                CollectionSupport.RemoveItem(info.ReturnType, collection, propertyValue.GetValueFor(info), propertyValue);
            }

            var item = this[index];

            item.RemoveNodeFromParent();
            item.ParentProperty = null;
            base.RemoveItem(index);

            if (CollectionChanged != null && !isClearing)
            {
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
            }
        }
Esempio n. 6
0
        void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
        {
            bool isDefaultValueSet = false;

            XamlProperty collectionProperty        = null;
            object       collectionInstance        = null;
            Type         collectionType            = null;
            XmlElement   collectionPropertyElement = null;
            var          elementChildNodes         = GetNormalizedChildNodes(element);

            if (defaultProperty == null && obj.Instance != null && CollectionSupport.IsCollectionType(obj.Instance.GetType()))
            {
                XamlObject       parentObj     = obj.ParentObject;
                var              parentElement = element.ParentNode;
                XamlPropertyInfo propertyInfo  = GetPropertyInfo(settings.TypeFinder, parentObj.Instance, parentObj.ElementType, parentElement.NamespaceURI, parentElement.LocalName);
                collectionProperty        = FindExistingXamlProperty(parentObj, propertyInfo);
                collectionInstance        = obj.Instance;
                collectionType            = obj.ElementType;
                collectionPropertyElement = element;
            }
            else if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty)
            {
                foreach (XmlNode childNode in elementChildNodes)
                {
                    XmlElement childElement = childNode as XmlElement;
                    if (childElement == null || !ObjectChildElementIsPropertyElement(childElement))
                    {
                        obj.AddProperty(collectionProperty = new XamlProperty(obj, defaultProperty));
                        collectionType     = defaultProperty.ReturnType;
                        collectionInstance = defaultProperty.GetValue(obj.Instance);
                        break;
                    }
                }
            }

            foreach (XmlNode childNode in elementChildNodes)
            {
                XmlElement childElement = childNode as XmlElement;
                if (childElement != null)
                {
                    if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
                    {
                        continue;
                    }

                    if (ObjectChildElementIsPropertyElement(childElement))
                    {
                        ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty);
                        continue;
                    }
                }
                if (initializeFromTextValueInsteadOfConstructor != null)
                {
                    continue;
                }
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (collectionProperty != null)
                    {
                        collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue);
                        CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue);
                    }
                    else
                    {
                        if (defaultProperty == null)
                        {
                            throw new XamlLoadException("This element does not have a default value, cannot assign to it");
                        }

                        if (isDefaultValueSet)
                        {
                            throw new XamlLoadException("default property may have only one value assigned");
                        }

                        obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
                        isDefaultValueSet = true;
                    }
                }
            }
        }
Esempio n. 7
0
        void ParseObjectChildElementAsPropertyElement(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, object defaultPropertyValue)
        {
            Debug.Assert(element.LocalName.Contains("."));
            // this is a element property syntax

            XamlPropertyInfo propertyInfo = GetPropertyInfo(settings.TypeFinder, obj.Instance, obj.ElementType, element.NamespaceURI, element.LocalName);
            bool             valueWasSet  = false;

            object       collectionInstance = null;
            XamlProperty collectionProperty = null;

            if (propertyInfo.IsCollection)
            {
                if (defaultProperty != null && defaultProperty.FullyQualifiedName == propertyInfo.FullyQualifiedName)
                {
                    collectionInstance = defaultPropertyValue;
                    foreach (XamlProperty existing in obj.Properties)
                    {
                        if (existing.propertyInfo == defaultProperty)
                        {
                            collectionProperty = existing;
                            break;
                        }
                    }
                }
                else
                {
                    collectionInstance = propertyInfo.GetValue(obj.Instance);
                }
                if (collectionProperty == null)
                {
                    obj.AddProperty(collectionProperty = new XamlProperty(obj, propertyInfo));
                }
                collectionProperty.ParserSetPropertyElement(element);
            }

            XmlSpace oldXmlSpace = currentXmlSpace;

            if (element.HasAttribute("xml:space"))
            {
                currentXmlSpace = (XmlSpace)Enum.Parse(typeof(XmlSpace), element.GetAttribute("xml:space"), true);
            }

            foreach (XmlNode childNode in element.ChildNodes)
            {
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (propertyInfo.IsCollection)
                    {
                        CollectionSupport.AddToCollection(propertyInfo.ReturnType, collectionInstance, childValue);
                        collectionProperty.ParserAddCollectionElement(element, childValue);
                    }
                    else
                    {
                        if (valueWasSet)
                        {
                            throw new XamlLoadException("non-collection property may have only one child element");
                        }
                        valueWasSet = true;
                        XamlProperty xp = new XamlProperty(obj, propertyInfo, childValue);
                        xp.ParserSetPropertyElement(element);
                        obj.AddProperty(xp);
                    }
                }
            }

            currentXmlSpace = oldXmlSpace;
        }
Esempio n. 8
0
        void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
        {
            XamlPropertyValue setDefaultValueTo         = null;
            object            defaultPropertyValue      = null;
            XamlProperty      defaultCollectionProperty = null;

            if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty)
            {
                defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
                obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
            }

            foreach (XmlNode childNode in GetNormalizedChildNodes(element))
            {
                // I don't know why the official XamlReader runs the property getter
                // here, but let's try to imitate it as good as possible
                if (defaultProperty != null && !defaultProperty.IsCollection)
                {
                    for (; combinedNormalizedChildNodes > 0; combinedNormalizedChildNodes--)
                    {
                        defaultProperty.GetValue(obj.Instance);
                    }
                }

                XmlElement childElement = childNode as XmlElement;
                if (childElement != null)
                {
                    if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
                    {
                        continue;
                    }

                    if (ObjectChildElementIsPropertyElement(childElement))
                    {
                        // I don't know why the official XamlReader runs the property getter
                        // here, but let's try to imitate it as good as possible
                        if (defaultProperty != null && !defaultProperty.IsCollection)
                        {
                            defaultProperty.GetValue(obj.Instance);
                        }
                        ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
                        continue;
                    }
                }
                if (initializeFromTextValueInsteadOfConstructor != null)
                {
                    continue;
                }
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (defaultProperty != null && defaultProperty.IsCollection)
                    {
                        defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
                        CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
                    }
                    else
                    {
                        if (setDefaultValueTo != null)
                        {
                            throw new XamlLoadException("default property may have only one value assigned");
                        }
                        setDefaultValueTo = childValue;
                    }
                }
            }

            if (defaultProperty != null && !defaultProperty.IsCollection && !element.IsEmpty)
            {
                // Runs even when defaultValueSet==false!
                // Again, no idea why the official XamlReader does this.
                defaultProperty.GetValue(obj.Instance);
            }
            if (setDefaultValueTo != null)
            {
                if (defaultProperty == null)
                {
                    throw new XamlLoadException("This element does not have a default value, cannot assign to it");
                }
                obj.AddProperty(new XamlProperty(obj, defaultProperty, setDefaultValueTo));
            }
        }
Esempio n. 9
0
		void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
		{
			bool isDefaultValueSet = false;
			
			XamlProperty collectionProperty = null;
			object collectionInstance = null;
			Type collectionType = null;
			XmlElement collectionPropertyElement = null;
			var elementChildNodes = GetNormalizedChildNodes(element);
			
			if (defaultProperty == null && obj.Instance != null && CollectionSupport.IsCollectionType(obj.Instance.GetType())) {
				XamlObject parentObj = obj.ParentObject;
				var parentElement = element.ParentNode;
				XamlPropertyInfo propertyInfo;
				if (parentObj != null) {
					propertyInfo = GetPropertyInfo(settings.TypeFinder, parentObj.Instance, parentObj.ElementType, parentElement.NamespaceURI, parentElement.LocalName);
					collectionProperty = FindExistingXamlProperty(parentObj, propertyInfo);
				}
				collectionInstance = obj.Instance;
				collectionType = obj.ElementType;
				collectionPropertyElement = element;
			} else if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
				foreach (XmlNode childNode in elementChildNodes) {
					currentParsedNode = childNode;
					XmlElement childElement = childNode as XmlElement;
					if (childElement == null || !ObjectChildElementIsPropertyElement(childElement)) {
						obj.AddProperty(collectionProperty = new XamlProperty(obj, defaultProperty));
						collectionType = defaultProperty.ReturnType;
						collectionInstance = defaultProperty.GetValue(obj.Instance);
						break;
					}
				}
			}

			currentParsedNode = element;

			if (collectionType != null && collectionInstance == null && elementChildNodes.Count() == 1)
			{
				var firstChild = elementChildNodes.First() as XmlElement;
				if (ObjectChildElementIsCollectionInstance(firstChild, collectionType))
				{
					collectionInstance = ParseObject(firstChild);
					collectionProperty.PropertyValue = (XamlPropertyValue) collectionInstance;
				}
				else
				{
					throw new XamlLoadException("Collection Instance is null");
				}
			}
			else
			{
				foreach (XmlNode childNode in elementChildNodes) {
					currentParsedNode = childNode;
					XmlElement childElement = childNode as XmlElement;
					if (childElement != null) {
						if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
							continue;
						
						if (ObjectChildElementIsPropertyElement(childElement)) {
							ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty);
							continue;
						}
					}
					if (initializeFromTextValueInsteadOfConstructor != null)
						continue;
					XamlPropertyValue childValue = ParseValue(childNode);
					if (childValue != null) {
						if (collectionProperty != null) {
							collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue);
							CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue);
						} else {
							if (defaultProperty == null)
								throw new XamlLoadException("This element does not have a default value, cannot assign to it");
							
							if (isDefaultValueSet)
								throw new XamlLoadException("default property may have only one value assigned");
							
							obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
							isDefaultValueSet = true;
						}
					}
				}
			}

			currentParsedNode = element;
		}
Esempio n. 10
0
		void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
		{
			XamlPropertyValue setDefaultValueTo = null;
			object defaultPropertyValue = null;
			XamlProperty defaultCollectionProperty = null;
			
			if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
				defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
				obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
			}
			
			foreach (XmlNode childNode in GetNormalizedChildNodes(element)) {
				
				// I don't know why the official XamlReader runs the property getter
				// here, but let's try to imitate it as good as possible
				if (defaultProperty != null && !defaultProperty.IsCollection) {
					for (; combinedNormalizedChildNodes > 0; combinedNormalizedChildNodes--) {
						defaultProperty.GetValue(obj.Instance);
					}
				}
				
				XmlElement childElement = childNode as XmlElement;
				if (childElement != null) {
					if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
						continue;
					
					if (ObjectChildElementIsPropertyElement(childElement)) {
						// I don't know why the official XamlReader runs the property getter
						// here, but let's try to imitate it as good as possible
						if (defaultProperty != null && !defaultProperty.IsCollection) {
							defaultProperty.GetValue(obj.Instance);
						}
						ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
						continue;
					}
				}
				if (initializeFromTextValueInsteadOfConstructor != null)
					continue;
				XamlPropertyValue childValue = ParseValue(childNode);
				if (childValue != null) {
					if (defaultProperty != null && defaultProperty.IsCollection) {
						defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
						CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
					} else {
						if (setDefaultValueTo != null)
							throw new XamlLoadException("default property may have only one value assigned");
						setDefaultValueTo = childValue;
					}
				}
			}
			
			if (defaultProperty != null && !defaultProperty.IsCollection && !element.IsEmpty) {
				// Runs even when defaultValueSet==false!
				// Again, no idea why the official XamlReader does this.
				defaultProperty.GetValue(obj.Instance);
			}
			if (setDefaultValueTo != null) {
				if (defaultProperty == null) {
					throw new XamlLoadException("This element does not have a default value, cannot assign to it");
				}
				obj.AddProperty(new XamlProperty(obj, defaultProperty, setDefaultValueTo));
			}
		}
Esempio n. 11
0
		void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
		{
			bool isDefaultValueSet = false;
			object defaultPropertyValue = null;
			XamlProperty defaultCollectionProperty = null;
			
			if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
				defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
				obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
			}
			
			foreach (XmlNode childNode in GetNormalizedChildNodes(element)) {
				XmlElement childElement = childNode as XmlElement;
				if (childElement != null) {
					if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
						continue;
					
					if (ObjectChildElementIsPropertyElement(childElement)) {
						ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
						continue;
					}
				}
				if (initializeFromTextValueInsteadOfConstructor != null)
					continue;
				XamlPropertyValue childValue = ParseValue(childNode);
				if (childValue != null) {
					if (defaultProperty != null && defaultProperty.IsCollection) {
						defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
						CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
					} else {
						if (defaultProperty == null)
							throw new XamlLoadException("This element does not have a default value, cannot assign to it");
						
						if (isDefaultValueSet)
							throw new XamlLoadException("default property may have only one value assigned");
						
						obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
						isDefaultValueSet = true;
					}
				}
			}
		}