PackageSerializationManager( ) { _serializersCacheManager = new SerializersCacheManager(this); _graphContextStack = new ContextStack(); this._rootSerializableObjectContext = null; }
CanSerializeProperty( MemberInfo memberInfo, SerializersCacheManager serializersCacheManager, out DesignerSerializationVisibility visibility, out Type serializerTypeForProperty, out TypeConverter typeConverterForProperty, out DefaultValueAttribute defaultValueAttr, out DesignerSerializationOptionsAttribute designerSerializationFlagsAttr ) { bool canSerializeProperty = false; // The conditions that we care about in those properties are as follows // 1. Properties that are decorated with the DesignerSerializationVisibility // and that are not hidden // visibility = DesignerSerializationVisibility.Visible; serializerTypeForProperty = null; typeConverterForProperty = null; defaultValueAttr = null; designerSerializationFlagsAttr = null; Attribute[] attributes = Attribute.GetCustomAttributes(memberInfo); for (int numberOfAttributes = 0; numberOfAttributes < attributes.Length; numberOfAttributes++) { // // Based on the attribute type, different properties could be set // Attribute attribute = attributes[numberOfAttributes]; if (attribute is DesignerSerializationVisibilityAttribute) { visibility = ((DesignerSerializationVisibilityAttribute)attribute).Visibility; } else if (attribute is DefaultValueAttribute) { defaultValueAttr = (DefaultValueAttribute)attribute; } else if (attribute is DesignerSerializationOptionsAttribute) { designerSerializationFlagsAttr = (DesignerSerializationOptionsAttribute)attribute; } } if (visibility != DesignerSerializationVisibility.Hidden) { canSerializeProperty = true; } return(canSerializeProperty); }
GetClrSerializableProperties( SerializersCacheManager serializersCacheManager ) { if (clrSerializableProperties == null) { PropertyInfo[] properties = type.GetProperties(); // // Separate out the serializable Clr properties // int IndexOfSerializableProperties = 0; int[] propertiesIndex = new int[properties.Length]; TypePropertyCache[] cachedProperties = new TypePropertyCache[properties.Length]; for (int indexInProperties = 0; indexInProperties < properties.Length; indexInProperties++) { PropertyInfo propertyInfo = properties[indexInProperties]; DesignerSerializationVisibility visibility = DesignerSerializationVisibility.Visible; Type serializerTypeForProperty = null; TypeConverter typeConverterForProperty = null; DefaultValueAttribute defaultValueAttr = null; DesignerSerializationOptionsAttribute designerSerializationFlagsAttr = null; if (CanSerializeProperty(propertyInfo, serializersCacheManager, out visibility, out serializerTypeForProperty, out typeConverterForProperty, out defaultValueAttr, out designerSerializationFlagsAttr) == true) { // // Figure out the Serializer or TypeConverter associated with the // type of that property. This would potentially be cached in 2 // different places // 1. The Type Cache // 2. The TypePropertyCache. // TypeCacheItem typeCacheItem = serializersCacheManager.GetTypeCacheItem(propertyInfo.PropertyType); serializerTypeForProperty = typeCacheItem.SerializerType; typeConverterForProperty = typeCacheItem.TypeConverter; // // We create a cache of this property and all the information we // deduced about it // TypePropertyCache propertyCache = new TypePropertyCache(propertyInfo, visibility, serializerTypeForProperty, typeConverterForProperty, defaultValueAttr, designerSerializationFlagsAttr); propertiesIndex[IndexOfSerializableProperties] = indexInProperties; cachedProperties[IndexOfSerializableProperties++] = propertyCache; } } clrSerializableProperties = new TypePropertyCache[IndexOfSerializableProperties]; for (int indexInClrProperties = 0; indexInClrProperties < IndexOfSerializableProperties; indexInClrProperties++) { clrSerializableProperties[indexInClrProperties] = cachedProperties[indexInClrProperties]; } } return(clrSerializableProperties); }
CanSerializeProperty( PropertyInfo propertyInfo, SerializersCacheManager serializersCacheManager, out DesignerSerializationVisibility visibility, out Type serializerTypeForProperty, out TypeConverter typeConverterForProperty, out DefaultValueAttribute defaultValueAttr, out DesignerSerializationOptionsAttribute designerSerializationFlagsAttr ) { bool canSerializeProperty = false; visibility = DesignerSerializationVisibility.Visible; serializerTypeForProperty = null; typeConverterForProperty = null; defaultValueAttr = null; designerSerializationFlagsAttr = null; // The conditions that we care about in those properties are as follows // 1. Readable properties // 2. None Indexable Properteis. // So we can't deal with properties that take name: Item OR // take the form this[index1, index2, ...] // 3. Properties that are not backed up by a dependency property // 4. Properties that are decorated with the DesignerSerializationVisibility // and that are not hidden // if (propertyInfo.CanRead && propertyInfo.GetIndexParameters().GetLength(0) == 0) { MemberInfo memberInfo = (MemberInfo)propertyInfo; Attribute[] attributes = Attribute.GetCustomAttributes(memberInfo); for (int numberOfAttributes = 0; numberOfAttributes < attributes.Length; numberOfAttributes++) { // // Based on the attribute type, different properties could be set // Attribute attribute = attributes[numberOfAttributes]; if (attribute is DesignerSerializationVisibilityAttribute) { visibility = ((DesignerSerializationVisibilityAttribute)attribute).Visibility; } else if (attribute is DefaultValueAttribute) { defaultValueAttr = (DefaultValueAttribute)attribute; } else if (attribute is DesignerSerializationOptionsAttribute) { designerSerializationFlagsAttr = (DesignerSerializationOptionsAttribute)attribute; } } object DependencyPropertyORPropertyInfo = DependencyProperty.FromName(propertyInfo.Name, propertyInfo.DeclaringType); if (DependencyPropertyORPropertyInfo == null && visibility != DesignerSerializationVisibility.Hidden && (propertyInfo.CanWrite || visibility == DesignerSerializationVisibility.Content)) { if (visibility != DesignerSerializationVisibility.Hidden) { canSerializeProperty = true; } } } return(canSerializeProperty); }