MetroSerializationNamespaceTable(
     MetroSerializationNamespaceTable parent
     )
 {
     Initialize(parent);
 }
 Initialize(
     MetroSerializationNamespaceTable parent
     )
 {
     _innerDictionary = new Hashtable(11);
 }
Ejemplo n.º 3
0
        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);
        }