~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/Services/DesignerSerializationService.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections;
 
6
using System.ComponentModel.Design.Serialization;
 
7
using System.ComponentModel.Design;
 
8
        
 
9
namespace ICSharpCode.Reports.Addin
 
10
{
 
11
        /// <summary>
 
12
        /// This class implements the IDesignerSerializationService interface.
 
13
        /// A designer loader that does not derive from the CodeDOMDesignerLoader class 
 
14
        /// (e.g. the XmlDesignerLoader) need to create an instance of this class
 
15
        /// and it to the available services otherwise cut/copy and paste will not work.
 
16
        /// </summary>
 
17
        public class DesignerSerializationService : IDesignerSerializationService
 
18
        {
 
19
                IServiceProvider serviceProvider;
 
20
                public DesignerSerializationService(IServiceProvider serviceProvider)
 
21
                {
 
22
                        if (serviceProvider == null) {
 
23
                                throw new ArgumentNullException("serviceProvider");
 
24
                        }
 
25
                        this.serviceProvider = serviceProvider;
 
26
                }
 
27
                
 
28
                /// <summary>
 
29
                /// Deserializes the serialization data object and returns a 
 
30
                /// collection of objects represented by that data. 
 
31
                /// </summary>
 
32
                public ICollection Deserialize(object serializationData)
 
33
                {
 
34
                        IDesignerHost host = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost));
 
35
                        if (host != null) {
 
36
                                ComponentSerializationService serializationService = (ComponentSerializationService)serviceProvider.GetService(typeof(ComponentSerializationService));
 
37
                                return serializationService.Deserialize((SerializationStore)serializationData,host.Container);
 
38
                        }
 
39
                        return null;
 
40
                }
 
41
                
 
42
                /// <summary>
 
43
                /// Serializes a collection of objects and stores them in a 
 
44
                /// serialization data object. 
 
45
                /// </summary>
 
46
                public object Serialize(ICollection objects)
 
47
                {
 
48
                        if (objects == null) {
 
49
                                throw new ArgumentNullException("objects");
 
50
                        }
 
51
                        ComponentSerializationService serializationService = (ComponentSerializationService)serviceProvider.GetService(typeof(ComponentSerializationService));
 
52
                        SerializationStore store = serializationService.CreateStore();
 
53
                        foreach (object value in objects) {
 
54
                                serializationService.Serialize(store, value);
 
55
                        }
 
56
                        store.Close();
 
57
                        return store;
 
58
                }
 
59
        }
 
60
}