SerializeProperty( SerializablePropertyContext serializablePropertyContext ) { if (serializablePropertyContext == null) { throw new ArgumentNullException("serializablePropertyContext"); } if (!serializablePropertyContext.IsComplex) { // // Non-Complex Properties are serialized as attributes // WriteSerializedAttribute(serializablePropertyContext); } else { // // Complex properties could be treated in different ways // based on their type. Examples of that are: // // // ReachSerializer serializer = SerializationManager.GetSerializer(serializablePropertyContext.Value); // If there is no serializer for this type, we won't serialize this property if (serializer != null) { serializer.SerializeObject(serializablePropertyContext); } } }
SerializeProperties( SerializableObjectContext serializableObjectContext ) { if (serializableObjectContext == null) { throw new ArgumentNullException("serializableObjectContext"); } SerializablePropertyCollection propertyCollection = serializableObjectContext.PropertiesCollection; if (propertyCollection != null) { for (propertyCollection.Reset(); propertyCollection.MoveNext();) { SerializablePropertyContext serializablePropertyContext = (SerializablePropertyContext)propertyCollection.Current; if (serializablePropertyContext != null) { SerializeProperty(serializablePropertyContext); } } } }
SerializeObject( SerializablePropertyContext serializedProperty ) { _syncSerializer.Initialize(); base.SerializeObject(serializedProperty); }
SerializableObjectContext( object target, SerializablePropertyContext serializablePropertyContext ) { Initialize(target, serializablePropertyContext); }
DiscoverObjectData( Object serializedObject, SerializablePropertyContext serializedProperty ) { // // Trying to figure out the parent of this node, which is at this stage // the same node previously pushed on the stack or in other words it is // the node that is currently on the top of the stack // SerializableObjectContext serializableObjectParentContext = (SerializableObjectContext)SerializationManager. GraphContextStack[typeof(SerializableObjectContext)]; // // Create the context for the current object // SerializableObjectContext serializableObjectContext = SerializableObjectContext.CreateContext(SerializationManager, serializedObject, serializableObjectParentContext, serializedProperty); // // Set the root object to be serialized at the level of the SerializationManager // if (SerializationManager.RootSerializableObjectContext == null) { SerializationManager.RootSerializableObjectContext = serializableObjectContext; } return(serializableObjectContext); }
WriteSerializedAttribute( SerializablePropertyContext serializablePropertyContext ) { if (serializablePropertyContext == null) { throw new ArgumentNullException("serializablePropertyContext"); } }
SerializeObject( SerializablePropertyContext serializedProperty ) { // // Do nothing here. // We do not support serializing visuals that come in as // properties out of context of a FixedPage or a DocumentPage // }
SerializeObject( SerializablePropertyContext serializedProperty ) { if (serializedProperty == null) { throw new ArgumentNullException("serializedProperty"); } SerializeObject(serializedProperty.Value); }
SerializeObject( SerializablePropertyContext serializedProperty ) { // // Create the ImageTable required by the Type Converters // The Image table at this time is shared / currentPage // ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageImageTable = new Dictionary<int, Uri>(); base.SerializeObject(serializedProperty); }
XpsTokenContext( PackageSerializationManager serializationManager, SerializablePropertyContext propertyContext ) { // // Make necessary checks and throw necessary exceptions // this.serializationManager = serializationManager; this.targetObject = propertyContext.TargetObject; this.objectValue = propertyContext.Value; this.propertyInfo = propertyContext.PropertyInfo; this.dependencyProperty = (propertyContext is SerializableDependencyPropertyContext) ? (DependencyProperty)((SerializableDependencyPropertyContext)propertyContext).DependencyProperty : null; }
SerializeObject( SerializablePropertyContext serializedProperty ) { if (serializedProperty == null) { throw new ArgumentNullException("serializedProperty"); } if (SerializationManager == null) { throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_MustHaveSerializationManager)); } // // At this stage discover the graph of properties of the object that // need to be serialized // SerializableObjectContext serializableObjectContext = DiscoverObjectData(serializedProperty.Value, serializedProperty); if (serializableObjectContext != null) { // // Push the object at hand on the context stack // SerializationManager.GraphContextStack.Push(serializableObjectContext); // // At this stage we should start streaming the markup representing the // object graph to the corresponding destination // PersistObjectData(serializableObjectContext); // // Pop the object from the context stack // SerializationManager.GraphContextStack.Pop(); // // Recycle the used SerializableObjectContext // SerializableObjectContext.RecycleContext(serializableObjectContext); } }
SerializeObject( SerializablePropertyContext serializedProperty ) { // // Create the ImageTable required by the Type Converters // The Image table at this time is shared / document // ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = new Dictionary <UInt32, Uri>(); ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = new Dictionary <int, Uri>(); // // Create the ColorContextTable required by the Type Converters // The Image table at this time is shared / document // ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.ColorContextTable = new Dictionary <int, Uri>(); base.SerializeObject(serializedProperty); }
SerializableObjectContext( string name, string prefix, object target, SerializablePropertyContext serializablePropertyContext ) : base(name, prefix) { // // Validate Input Arguments // if (target == null) { throw new ArgumentNullException("target"); } _targetObject = target; _isComplexValue = false; _backingPropertyContext = serializablePropertyContext; }
GetValueOfAttributeAsString( SerializablePropertyContext serializablePropertyContext ) { if (serializablePropertyContext == null) { throw new ArgumentNullException("serializablePropertyContext"); } String valueAsString = null; Object targetObjectContainingProperty = serializablePropertyContext.TargetObject; Object propertyValue = serializablePropertyContext.Value; if (propertyValue != null) { TypeConverter typeConverter = serializablePropertyContext.TypeConverter; valueAsString = typeConverter.ConvertToInvariantString(new XpsTokenContext(SerializationManager, serializablePropertyContext), propertyValue); if (typeof(Type).IsInstanceOfType(propertyValue)) { int index = valueAsString.LastIndexOf('.'); if (index > 0) { valueAsString = valueAsString.Substring(index + 1); } valueAsString = XpsSerializationManager.TypeOfString + valueAsString + "}"; } } else { valueAsString = XpsSerializationManager.NullString; } return(valueAsString); }
InitializeSerializableClrProperties( ) { TypePropertyCache[] clrProperties = _serializationManager.CacheManager.GetClrSerializableProperties(_target); if (clrProperties != null) { for (int indexInClrSerializableProperties = 0; indexInClrSerializableProperties < clrProperties.Length; indexInClrSerializableProperties++) { TypePropertyCache propertyCache = clrProperties[indexInClrSerializableProperties]; // // Create SerializablePropertyContext out of the cache retrieved // SerializablePropertyContext propertyContext = new SerializablePropertyContext(_target, propertyCache); propertyContext.Name = propertyContext.TypePropertyCache.PropertyInfo.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 (propertyContext.IsComplexProperty(_serializationManager)) { propertyContext.IsComplex = true; _complexPropertyCollection.Enqueue(propertyContext); } else { propertyContext.IsComplex = false; _simplePropertyCollection.Enqueue(propertyContext); } } } }
Initialize( object target, SerializablePropertyContext serializablePropertyContext ) { Initialize(); _targetObject = target; _isComplexValue = false; _backingPropertyContext = serializablePropertyContext; if (_backingPropertyContext != null) { _isComplexValue = _backingPropertyContext.IsComplex; _isReadOnlyValue = _backingPropertyContext.IsReadOnly; } else { _isComplexValue = true; _isReadOnlyValue = false; } }
WriteSerializedAttribute( SerializablePropertyContext serializablePropertyContext ) { if (serializablePropertyContext == null) { throw new ArgumentNullException("serializablePropertyContext"); } String attributeValue = String.Empty; attributeValue = GetValueOfAttributeAsString(serializablePropertyContext); if ((attributeValue != null) && (attributeValue.Length > 0)) { // // Emit name="value" attribute // XmlWriter.WriteAttributeString(serializablePropertyContext.Name, attributeValue); } }
SerializeNextProperty( SerializableObjectContext serializableObjectContext ) { SerializablePropertyCollection propertyCollection = serializableObjectContext.PropertiesCollection; if (propertyCollection.MoveNext()) { SerializablePropertyContext serializablePropertyContext = (SerializablePropertyContext)propertyCollection.Current; if (serializablePropertyContext != null) { ReachSerializerContext context = new ReachSerializerContext(this, serializableObjectContext, SerializerAction.serializeNextProperty); _serializationManager.OperationStack.Push(context); SerializeProperty(serializablePropertyContext); } } }
CreateContext( PackageSerializationManager serializationManager, object serializableObject, SerializableObjectContext serializableObjectParentContext, SerializablePropertyContext serializablePropertyContext ) { // // Check for element pre-existance to avoid infinite loops // in the process of serialization // int stackIndex = 0; object currentObject = null; for (currentObject = serializationManager.GraphContextStack[stackIndex]; currentObject != null; currentObject = serializationManager.GraphContextStack[++stackIndex]) { SerializableObjectContext currentObjectContext = currentObject as SerializableObjectContext; if (currentObjectContext != null && currentObjectContext.TargetObject == serializableObject) { throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_CycleDetectedInSerialization)); } } SerializableObjectContext serializableObjectContext; lock (_stackLock) { serializableObjectContext = _recycableSerializableObjectContexts.Count == 0 ? null : (SerializableObjectContext)_recycableSerializableObjectContexts.Pop(); } if (serializableObjectContext == null) { serializableObjectContext = new SerializableObjectContext(serializableObject, serializablePropertyContext); } else { serializableObjectContext.Initialize(serializableObject, serializablePropertyContext); } { // // Namespace related creation within the context // MetroSerializationNamespaceTable parentNamespaceTable = serializableObjectParentContext != null ? serializableObjectParentContext.NamespaceTable : null; if (serializableObjectContext.NamespaceTable == null) { serializableObjectContext.NamespaceTable = new MetroSerializationNamespaceTable(parentNamespaceTable); } } { // // Properties related creation within the context // if (serializableObjectContext.PropertiesCollection == null) { serializableObjectContext.PropertiesCollection = new SerializablePropertyCollection(serializationManager, serializableObject); } else { serializableObjectContext.PropertiesCollection.Initialize(serializationManager, serializableObject); } } serializableObjectContext.Name = serializableObjectContext.TargetObject.GetType().Name; return(serializableObjectContext); }
WriteSerializedAttribute( SerializablePropertyContext serializablePropertyContext ) { _syncSerializer.WriteSerializedAttribute(serializablePropertyContext); }
SerializeObject( SerializablePropertyContext serializedProperty ) { BeginSerializeObject(serializedProperty); }