CanSerializeDependencyProperty( Object serializableObject, TypeDependencyPropertyCache dependencyProperty ) { return(CanSerializeDependencyProperty(serializableObject, dependencyProperty, _reachSerializationServices)); }
CanSerializeDependencyProperty( Object serializableObject, TypeDependencyPropertyCache dependencyProperty ) { return(true); }
SerializableDependencyPropertyContext( string name, string prefix, object target, TypeDependencyPropertyCache propertyCache) : base(name, prefix, target, propertyCache) { }
InitializeSerializableDependencyProperties( ) { TypeDependencyPropertyCache[] dependencyProperties = _serializationManager. CacheManager. GetSerializableDependencyProperties(_target); if (dependencyProperties != null) { for (int indexInSerializableDependencyProperties = 0; indexInSerializableDependencyProperties < dependencyProperties.Length; indexInSerializableDependencyProperties++) { TypeDependencyPropertyCache dependencyPropertyCache = dependencyProperties[indexInSerializableDependencyProperties]; // // Create SerializableDependencyPropertyContext out of the cache retrieved // SerializableDependencyPropertyContext dependencyPropertyContext = new SerializableDependencyPropertyContext(_target, dependencyPropertyCache); dependencyPropertyContext.Name = ((DependencyProperty)((TypeDependencyPropertyCache)dependencyPropertyContext.TypePropertyCache). DependencyProperty).Name; // // We have to differentiate between simple properties and complex properties. // o Simple properties would be considered as attributes within the markup and // would not require new writers // o Complex properties would be considered elements within the markup and might // require a new writer // if (dependencyPropertyContext.IsComplexProperty(_serializationManager)) { dependencyPropertyContext.IsComplex = true; _complexPropertyCollection.Enqueue(dependencyPropertyContext); } else { dependencyPropertyContext.IsComplex = false; _simplePropertyCollection.Enqueue(dependencyPropertyContext); } } } }
CanSerializeDependencyProperty( Object serializableObject, TypeDependencyPropertyCache dependencyProperty, ReachSerializationServices reachSerializationServices ) { bool canSerialize = false; if (serializableObject != null && dependencyProperty != null && ((dependencyProperty.PropertyInfo != null) || (((DependencyProperty)(dependencyProperty.DependencyProperty)).Name != null))) { String name = (dependencyProperty.PropertyInfo != null) ? dependencyProperty.PropertyInfo.Name : ((DependencyProperty)(dependencyProperty.DependencyProperty)).Name; Hashtable dependencyPropertiesTable = (Hashtable)reachSerializationServices. TypeSerializableDependencyProperties[serializableObject.GetType()]; if (dependencyPropertiesTable != null) { if (dependencyPropertiesTable.Contains(name)) { canSerialize = true; } } else { canSerialize = true; } } else { canSerialize = true; } return(canSerialize); }
GetTypeDependencyPropertiesCacheItem( Object serializableObject ) { if (serializableObject == null) { throw new ArgumentNullException("serializableObject"); } Type type = serializableObject.GetType(); TypeDependencyPropertiesCacheItem cachedItem = (TypeDependencyPropertiesCacheItem)_typesDependencyPropertiesCacheTable[type]; if (cachedItem == null) { // // This means that the type was not seen before // We have to create a new entry to that type // DependencyObject objectAsDependencyObject = serializableObject as DependencyObject; if (objectAsDependencyObject != null) { // // First we have to figure out if this dependency // object has any dependency properties that can be // serializable and this has to happen before creating // any cache // DependencyPropertyList list = new DependencyPropertyList(1); for (LocalValueEnumerator localValues = objectAsDependencyObject.GetLocalValueEnumerator(); localValues.MoveNext();) { DependencyProperty dependencyProperty = localValues.Current.Property; list.Add(dependencyProperty); } if (list.Count > 0) { int numOfSerializableDependencyProperties = 0; TypeDependencyPropertyCache[] dependencyPropertiesCache = new TypeDependencyPropertyCache[list.Count]; for (int indexInDependencyPropertyList = 0; indexInDependencyPropertyList < list.Count; indexInDependencyPropertyList++) { DependencyProperty dependencyProperty = list.List[indexInDependencyPropertyList]; DesignerSerializationVisibility visibility = DesignerSerializationVisibility.Visible; Type serializerTypeForProperty = null; TypeConverter typeConverterForProperty = null; DefaultValueAttribute defaultValueAttr = null; DesignerSerializationOptionsAttribute designerSerializationFlagsAttr = null; Type propertyType = dependencyProperty.PropertyType; // // Get the static setter member for the DependencyProperty // MemberInfo memberInfo = dependencyProperty. OwnerType. GetMethod("Get" + dependencyProperty.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy); // Note: This is because the IService model does not abide // by this pattern of declaring the DependencyProperty on // the OwnerType. That is the only exception case. if (memberInfo == null) { // // Create a PropertyInfo // PropertyInfo propertyInfo = null; PropertyInfo[] properties = dependencyProperty.OwnerType.GetProperties(); String name = dependencyProperty.Name; for (int i = 0; i < properties.Length && propertyInfo == null; i++) { if (properties[i].Name == name) { propertyInfo = properties[i]; } } if (propertyInfo != null) { Debug.Assert(propertyInfo.PropertyType == dependencyProperty.PropertyType, "The property type of the CLR wrapper must match that of the DependencyProperty itself."); memberInfo = propertyInfo; // // We have to special case Print Tickets here. // Print Tickets are defined on as dependency properties on // fixed objects of types: // o FixedDocumentSequence // o FixedDocument // o FixedPage // and in order to eliminate the dependency between // PresentationFramework and System.printing assemblies, // those dependency properties are defined as of type "object" // and hence if we are here and we have a property of name // "PrintTicket" and owned by one of the above mentioned types // we try to get the serializer for the PrintTicket object // if (propertyInfo.Name == XpsNamedProperties.PrintTicketProperty && ((dependencyProperty.OwnerType == typeof(System.Windows.Documents.FixedPage)) || (dependencyProperty.OwnerType == typeof(System.Windows.Documents.FixedDocument)) || (dependencyProperty.OwnerType == typeof(System.Windows.Documents.FixedDocumentSequence)))) { propertyType = typeof(PrintTicket); } } } if (memberInfo != null && TypeDependencyPropertyCache. CanSerializeProperty(memberInfo, this, out visibility, out serializerTypeForProperty, out typeConverterForProperty, out defaultValueAttr, out designerSerializationFlagsAttr) == true) { TypeCacheItem typeCacheItem = GetTypeCacheItem(propertyType); serializerTypeForProperty = serializerTypeForProperty == null ? typeCacheItem.SerializerType : serializerTypeForProperty; typeConverterForProperty = typeConverterForProperty == null ? typeCacheItem.TypeConverter : typeConverterForProperty; TypeDependencyPropertyCache dependencyPropertyCache = new TypeDependencyPropertyCache(memberInfo, dependencyProperty, visibility, serializerTypeForProperty, typeConverterForProperty, defaultValueAttr, designerSerializationFlagsAttr); dependencyPropertiesCache[numOfSerializableDependencyProperties++] = dependencyPropertyCache; } } if (numOfSerializableDependencyProperties > 0) { TypeDependencyPropertyCache[] serializableDependencyPropertiesCache = new TypeDependencyPropertyCache[numOfSerializableDependencyProperties]; for (int indexInSerializableProperties = 0; indexInSerializableProperties < numOfSerializableDependencyProperties; indexInSerializableProperties++) { serializableDependencyPropertiesCache[indexInSerializableProperties] = dependencyPropertiesCache[indexInSerializableProperties]; } cachedItem = new TypeDependencyPropertiesCacheItem(type, serializableDependencyPropertiesCache); _typesDependencyPropertiesCacheTable[type] = cachedItem; } } } } return(cachedItem); }
GetSerializableDependencyProperties( Object serializableObject ) { TypeDependencyPropertyCache[] serializableDependencyProperties = null; TypeDependencyPropertiesCacheItem item = GetTypeDependencyPropertiesCacheItem(serializableObject); if (item != null) { TypeDependencyPropertyCache[] dependencyProperties = item.GetSerializableDependencyProperties(); int[] serializableIndeces = new int[dependencyProperties.Length]; int serializablePropertiesIndex = 0; // // Not everything we get can be serializable, so we have to figure out which // ones are by checking if we can also serialize the value of the property // values would be added to the cache as well. // for (int indexInDependencyProperties = 0; indexInDependencyProperties < dependencyProperties.Length; indexInDependencyProperties++) { if (TypeDependencyPropertyCache. CanSerializeValue(serializableObject, dependencyProperties[indexInDependencyProperties]) && _serializationManager.CanSerializeDependencyProperty(serializableObject, dependencyProperties[indexInDependencyProperties])) { serializableIndeces[serializablePropertiesIndex++] = indexInDependencyProperties; } } serializableDependencyProperties = new TypeDependencyPropertyCache[serializablePropertiesIndex]; for (int indexInSerializableDependencyProperties = 0; indexInSerializableDependencyProperties < serializablePropertiesIndex; indexInSerializableDependencyProperties++) { TypeDependencyPropertyCache propertyCache = dependencyProperties[serializableIndeces[indexInSerializableDependencyProperties]]; TypeDependencyPropertyCache serializablePropertyCache = new TypeDependencyPropertyCache(propertyCache.MemberInfo, propertyCache.DependencyProperty, propertyCache.Visibility, propertyCache.SerializerTypeForProperty, propertyCache.TypeConverterForProperty, propertyCache.DefaultValueAttr, propertyCache.DesignerSerializationOptionsAttr); serializablePropertyCache.PropertyValue = propertyCache.PropertyValue; serializableDependencyProperties[indexInSerializableDependencyProperties] = serializablePropertyCache; } // // Clear all set values // for (int indexInDependencyProperties = 0; indexInDependencyProperties < dependencyProperties.Length; indexInDependencyProperties++) { dependencyProperties[indexInDependencyProperties].PropertyValue = null; } } return(serializableDependencyProperties); }
SerializableDependencyPropertyContext( object target, TypeDependencyPropertyCache propertyCache) : base(target, propertyCache) { }
CanSerializeValue( object serializableObject, TypeDependencyPropertyCache propertyCache ) { bool canSerializeValue = false; // // For readonly properties check for DesignerSerializationVisibility.Content // bool isReadOnly = ((DependencyProperty)propertyCache.DependencyProperty).ReadOnly; if (isReadOnly && propertyCache.Visibility == DesignerSerializationVisibility.Content) { // // If there is a Visibility.Content attribute honor it and // populate the property value in this data structure // // DependencyObject targetDO = serializableObject as DependencyObject; propertyCache.PropertyValue = targetDO.ReadLocalValue((DependencyProperty)propertyCache.DependencyProperty); canSerializeValue = true; } else if (propertyCache.DefaultValueAttr == null) { // // Populate the property value in this data structure // DependencyObject targetDO = serializableObject as DependencyObject; propertyCache.PropertyValue = targetDO.ReadLocalValue((DependencyProperty)propertyCache.DependencyProperty); canSerializeValue = true; } else { // // Populate the property value in this data structure // as it is required to evaluate the default value // DependencyObject targetDO = serializableObject as DependencyObject; propertyCache.PropertyValue = targetDO.ReadLocalValue((DependencyProperty)propertyCache.DependencyProperty); // // For Clr properties with a DefaultValueAttribute // check if the current value equals the default // canSerializeValue = !object.Equals(propertyCache.DefaultValueAttr.Value, propertyCache.PropertyValue); if (!canSerializeValue) { propertyCache.PropertyValue = null; } } if (canSerializeValue) { if ((propertyCache.PropertyValue == null) || (propertyCache.PropertyValue == System.Windows.DependencyProperty.UnsetValue)) { canSerializeValue = false; } } return(canSerializeValue); }