Пример #1
0
            private object DeserializeEntry(IDesignerSerializationManager manager, ObjectEntry objectEntry)
            {
                object deserialized = null;

                if (objectEntry.IsEntireObject)
                {
                    CodeDomSerializer serializer = (CodeDomSerializer)manager.GetSerializer(objectEntry.Type,
                                                                                            typeof(CodeDomSerializer));
                    if (serializer != null)
                    {
                        deserialized = serializer.Deserialize(manager, objectEntry.Serialized);
                        // check if the name of the object has changed
                        // (if it e.g clashes with another name)
                        string newName = manager.GetName(deserialized);
                        if (newName != objectEntry.Name)
                        {
                            objectEntry.Name = newName;
                        }
                    }
                }
                else
                {
                    foreach (MemberEntry memberEntry in objectEntry.Members.Values)
                    {
                        CodeDomSerializer serializer = (CodeDomSerializer)manager.GetSerializer(objectEntry.Type,
                                                                                                typeof(CodeDomSerializer));
                        if (serializer != null)
                        {
                            serializer.Deserialize(manager, memberEntry.Serialized);
                        }
                    }
                }

                return(deserialized);
            }
Пример #2
0
        protected override void PerformLoad(IDesignerSerializationManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            CodeCompileUnit document = this.Parse();

            if (document == null)
            {
                throw new NotSupportedException("The language did not provide a code parser for this file");
            }

            string namespaceName             = null;
            CodeTypeDeclaration rootDocument = GetFirstCodeTypeDecl(document, out namespaceName);

            if (rootDocument == null)
            {
                throw new InvalidOperationException("Cannot find a declaration in a namespace to load.");
            }

            _rootSerializer = manager.GetSerializer(manager.GetType(rootDocument.BaseTypes[0].BaseType),
                                                    typeof(RootCodeDomSerializer)) as CodeDomSerializer;
            if (_rootSerializer == null)
            {
                throw new InvalidOperationException("Serialization not supported for this class");
            }

            _rootSerializer.Deserialize(manager, rootDocument);

            base.SetBaseComponentClassName(namespaceName + "." + rootDocument.Name);
        }