Пример #1
0
        private static Dictionary <string, object> GetChildPropertiesAndContent(object element, XmlWriter writer, Type type, ref object contentPropertyValue)
        {
            ContentPropertyAttribute    attribute  = WindowProfileSerializer.GetAttribute <ContentPropertyAttribute>((MemberInfo)type);
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            foreach (PropertyInfo property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (WindowProfileSerializer.IsPropertySerializable(property))
                {
                    object obj = property.GetValue(element, (object[])null);
                    if (!WindowProfileSerializer.IsDefaultValue(property, obj))
                    {
                        if (WindowProfileSerializer.IsContentProperty(attribute, property))
                        {
                            contentPropertyValue = obj;
                        }
                        else
                        {
                            TypeConverter converter = TypeDescriptor.GetConverter(obj == null ? property.PropertyType : obj.GetType());
                            if (converter.CanConvertTo(typeof(string)) && converter.CanConvertFrom(typeof(string)))
                            {
                                writer.WriteStartAttribute(property.Name);
                                WindowProfileSerializer.WriteAttributeValue(converter, obj, writer);
                                writer.WriteEndAttribute();
                            }
                            else
                            {
                                dictionary[property.Name] = obj;
                            }
                        }
                    }
                }
            }
            return(dictionary);
        }
Пример #2
0
        private static bool IsPropertySerializable(PropertyInfo property)
        {
            DesignerSerializationVisibilityAttribute attribute = WindowProfileSerializer.GetAttribute <DesignerSerializationVisibilityAttribute>((MemberInfo)property);

            if (attribute != null && attribute.Visibility == DesignerSerializationVisibility.Hidden || !property.CanRead)
            {
                return(false);
            }
            if (!property.CanWrite)
            {
                return(WindowProfileSerializer.IsSequenceType(property.PropertyType));
            }
            return(true);
        }
Пример #3
0
        private static bool IsDefaultValue(PropertyInfo property, object value)
        {
            DefaultValueAttribute attribute = WindowProfileSerializer.GetAttribute <DefaultValueAttribute>((MemberInfo)property);

            if (attribute == null)
            {
                return(false);
            }
            if (object.ReferenceEquals(value, attribute.Value))
            {
                return(true);
            }
            if (value != null)
            {
                return(value.Equals(attribute.Value));
            }
            return(false);
        }
Пример #4
0
 private static bool IsTypeNonSerializable(Type type)
 {
     return(WindowProfileSerializer.GetAttribute <NonXamlSerializedAttribute>((MemberInfo)type) != null);
 }