Esempio n. 1
0
            internal ICollection Deserialize(IServiceProvider provider, IContainer container,
                                             bool validateRecycledTypes, bool applyDefaults)
            {
                List <object> objectInstances = new List <object> ();

                if (provider == null || _objects == null)
                {
                    return(objectInstances);
                }
                _provider = provider;

                // Use a new serialization manager to prevent from "deadlocking" the surface one
                // by trying to create new session when one currently exists
                //
                InstanceRedirectorDesignerSerializationManager manager =
                    new InstanceRedirectorDesignerSerializationManager(provider, container, validateRecycledTypes);

                ((IDesignerSerializationManager)manager).AddSerializationProvider(CodeDomSerializationProvider.Instance);
                IDisposable session = manager.CreateSession();

                foreach (ObjectEntry entry in _objects.Values)
                {
                    objectInstances.Add(DeserializeEntry(manager, entry));
                }
                _errors = manager.Errors;
                ReportErrors(provider, _errors);
                session.Dispose();
                return(objectInstances);
            }
			internal ICollection Deserialize (IServiceProvider provider, IContainer container, 
							  bool validateRecycledTypes, bool applyDefaults)
			{
				List<object> objectInstances = new List<object> ();

				if (provider == null || _objects == null)
					return objectInstances;
				_provider = provider;

				// Use a new serialization manager to prevent from "deadlocking" the surface one
				// by trying to create new session when one currently exists
				// 
				InstanceRedirectorDesignerSerializationManager manager = 
					new InstanceRedirectorDesignerSerializationManager (provider, container, validateRecycledTypes);
				((IDesignerSerializationManager)manager).AddSerializationProvider (CodeDomSerializationProvider.Instance);
				IDisposable session = manager.CreateSession ();
				foreach (ObjectEntry entry in _objects.Values)
					objectInstances.Add (DeserializeEntry (manager, entry));
				_errors = manager.Errors;
				session.Dispose ();
				return objectInstances;
			}
			private void Serialize (IServiceProvider provider)
			{
				if (provider == null || _objects == null)
					return;

				// Use a new serialization manager to prevent from "deadlocking" the surface one
				// by trying to create new session when one currently exists
				// 
				InstanceRedirectorDesignerSerializationManager manager = 
					new InstanceRedirectorDesignerSerializationManager (provider, null, false);
				((IDesignerSerializationManager)manager).AddSerializationProvider (CodeDomSerializationProvider.Instance);
				IDisposable session = manager.CreateSession ();
				foreach (ObjectEntry objectEntry in _objects.Values) {
					if (objectEntry.IsEntireObject) {
						CodeDomSerializer serializer = (CodeDomSerializer) ((IDesignerSerializationManager)manager).GetSerializer (objectEntry.Type, 
													typeof (CodeDomSerializer));
						if (serializer != null) {
							object serialized = null;
							if (objectEntry.Absolute)
								serialized = serializer.SerializeAbsolute (manager, 
													   objectEntry.Instance);
							else
								serialized = serializer.Serialize (manager, objectEntry.Instance);
							objectEntry.Serialized = serialized;
						}
					} else {
						foreach (MemberEntry memberEntry in objectEntry.Members.Values) {
							CodeDomSerializer serializer = (CodeDomSerializer) ((IDesignerSerializationManager)manager).GetSerializer (
								objectEntry.Type, typeof (CodeDomSerializer));
							if (serializer != null) {
								object serialized = null;
								if (memberEntry.Absolute) {
									serialized = serializer.SerializeMemberAbsolute (manager, 
															 objectEntry.Instance, 
															 memberEntry.Descriptor);
								} else {
									serialized = serializer.SerializeMember (manager,
														 objectEntry.Instance, 
														 memberEntry.Descriptor);
								}
								memberEntry.Serialized = serialized;
							}
						}
					}
				}
				_errors = manager.Errors;
				session.Dispose ();
			}
Esempio n. 4
0
            private void Serialize(IServiceProvider provider)
            {
                if (provider == null || _objects == null)
                {
                    return;
                }

                // Use a new serialization manager to prevent from "deadlocking" the surface one
                // by trying to create new session when one currently exists
                //
                InstanceRedirectorDesignerSerializationManager manager =
                    new InstanceRedirectorDesignerSerializationManager(provider, null, false);

                ((IDesignerSerializationManager)manager).AddSerializationProvider(CodeDomSerializationProvider.Instance);
                IDisposable session = manager.CreateSession();

                foreach (ObjectEntry objectEntry in _objects.Values)
                {
                    if (objectEntry.IsEntireObject)
                    {
                        CodeDomSerializer serializer = (CodeDomSerializer)((IDesignerSerializationManager)manager).GetSerializer(objectEntry.Type,
                                                                                                                                 typeof(CodeDomSerializer));
                        if (serializer != null)
                        {
                            object serialized = null;
                            if (objectEntry.Absolute)
                            {
                                serialized = serializer.SerializeAbsolute(manager,
                                                                          objectEntry.Instance);
                            }
                            else
                            {
                                serialized = serializer.Serialize(manager, objectEntry.Instance);
                            }
                            objectEntry.Serialized = serialized;
                        }
                    }
                    else
                    {
                        foreach (MemberEntry memberEntry in objectEntry.Members.Values)
                        {
                            CodeDomSerializer serializer = (CodeDomSerializer)((IDesignerSerializationManager)manager).GetSerializer(
                                objectEntry.Type, typeof(CodeDomSerializer));
                            if (serializer != null)
                            {
                                object serialized = null;
                                if (memberEntry.Absolute)
                                {
                                    serialized = serializer.SerializeMemberAbsolute(manager,
                                                                                    objectEntry.Instance,
                                                                                    memberEntry.Descriptor);
                                }
                                else
                                {
                                    serialized = serializer.SerializeMember(manager,
                                                                            objectEntry.Instance,
                                                                            memberEntry.Descriptor);
                                }
                                memberEntry.Serialized = serialized;
                            }
                        }
                    }
                }
                _errors = manager.Errors;
                ReportErrors(provider, _errors);
                session.Dispose();
            }