コード例 #1
0
		private void WriteObjectProperties(XmlWriter xmlWriter, EntryPropertyType type, object obj)
		{
			PropertyInfo[] properties = obj.GetType().GetProperties();
			foreach (PropertyInfo p in properties) {
				//Check to see if the property has an entry property attribute
				object[] attributes = p.GetCustomAttributes(typeof(EntryPropertyAttribute), true);
				if (attributes.Length == 0)
					continue;

				//Check to see if the property is an attribute
				EntryPropertyAttribute ep = (EntryPropertyAttribute)attributes[0];
				if (type == EntryPropertyType.Attribute) {
					if (ep.Type != type)
						continue;
				} else if (type == EntryPropertyType.Element) {
					if (ep.Type != EntryPropertyType.Element && ep.Type != EntryPropertyType.SubElement)
						continue;
				}

				//Get value
				object value = p.GetValue(obj, null);
				if (value == null)
					continue;

				//Check to see if the value is different from the default value
				if (ep.DefaultValue != null) {
					if (ep.DefaultValue.Equals(value))
						continue;
				}

				switch (ep.Type) {
					case EntryPropertyType.Attribute:
						xmlWriter.WriteAttributeString(p.Name, value.ToString());
						break;
					case EntryPropertyType.Element:
						xmlWriter.WriteElementString(p.Name, value.ToString());
						break;
					case EntryPropertyType.SubElement:
						xmlWriter.WriteStartElement(p.Name);
						WriteLevelChild(xmlWriter, value);
						xmlWriter.WriteEndElement();
						break;
				}
			}
		}
コード例 #2
0
		public EntryPropertyAttribute(EntryPropertyType type, Type valueType, string value)
		{
			mDefaultValue = TypeDescriptor.GetConverter(valueType).ConvertFromInvariantString(value);
		}
コード例 #3
0
		public EntryPropertyAttribute(EntryPropertyType type, object defaultValue)
		{
			mType = type;
			mDefaultValue = defaultValue;
		}
コード例 #4
0
 public EntryPropertyAttribute(EntryPropertyType type, Type valueType, string value)
 {
     mDefaultValue = TypeDescriptor.GetConverter(valueType).ConvertFromInvariantString(value);
 }
コード例 #5
0
 public EntryPropertyAttribute(EntryPropertyType type, object defaultValue)
 {
     mType         = type;
     mDefaultValue = defaultValue;
 }
コード例 #6
0
        private void WriteObjectProperties(XmlWriter xmlWriter, EntryPropertyType type, object obj)
        {
            PropertyInfo[] properties = obj.GetType().GetProperties();
            foreach (PropertyInfo p in properties)
            {
                //Check to see if the property has an entry property attribute
                object[] attributes = p.GetCustomAttributes(typeof(EntryPropertyAttribute), true);
                if (attributes.Length == 0)
                {
                    continue;
                }

                //Check to see if the property is an attribute
                EntryPropertyAttribute ep = (EntryPropertyAttribute)attributes[0];
                if (type == EntryPropertyType.Attribute)
                {
                    if (ep.Type != type)
                    {
                        continue;
                    }
                }
                else if (type == EntryPropertyType.Element)
                {
                    if (ep.Type != EntryPropertyType.Element && ep.Type != EntryPropertyType.SubElement)
                    {
                        continue;
                    }
                }

                //Get value
                object value = p.GetValue(obj, null);
                if (value == null)
                {
                    continue;
                }

                //Check to see if the value is different from the default value
                if (ep.DefaultValue != null)
                {
                    if (ep.DefaultValue.Equals(value))
                    {
                        continue;
                    }
                }

                switch (ep.Type)
                {
                case EntryPropertyType.Attribute:
                    xmlWriter.WriteAttributeString(p.Name, value.ToString());
                    break;

                case EntryPropertyType.Element:
                    xmlWriter.WriteElementString(p.Name, value.ToString());
                    break;

                case EntryPropertyType.SubElement:
                    xmlWriter.WriteStartElement(p.Name);
                    WriteLevelChild(xmlWriter, value);
                    xmlWriter.WriteEndElement();
                    break;
                }
            }
        }