-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridLayoutSerializer.cs
More file actions
47 lines (44 loc) · 2.28 KB
/
GridLayoutSerializer.cs
File metadata and controls
47 lines (44 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Text;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.IO;
using DevExpress.Utils.Serializing;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.Utils.Serializing.Helpers;
namespace WindowsFormsApplication1
{
public class GridLayoutSerializer : XmlXtraSerializer
{
public static void SaveLayout(ColumnView view, Stream stream)
{
GridLayoutSerializer serializer = new GridLayoutSerializer();
serializer.Serialize(stream, serializer.GetFilterProps(view), "View");
}
protected XtraPropertyInfoCollection GetFilterProps(ColumnView view)
{
XtraPropertyInfoCollection store = new XtraPropertyInfoCollection();
ArrayList propList = new ArrayList();
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(view);
propList.Add(properties.Find("Columns", false));
propList.Add(properties.Find("OptionsView", false));
propList.Add(properties.Find("ActiveFilterEnabled", false));
propList.Add(properties.Find("ActiveFilterString", false));
propList.Add(properties.Find("MRUFilters", false));
propList.Add(properties.Find("ActiveFilter", false));
MethodInfo mi = typeof(SerializeHelper).GetMethod("SerializeProperty", BindingFlags.NonPublic | BindingFlags.Instance);
MethodInfo miGetXtraSerializableProperty = typeof(SerializeHelper).GetMethod("GetXtraSerializableProperty", BindingFlags.NonPublic | BindingFlags.Instance);
SerializeHelper helper = new SerializeHelper(view);
(view as IXtraSerializable).OnStartSerializing();
foreach (PropertyDescriptor prop in propList)
{
XtraSerializableProperty newXtraSerializableProperty = miGetXtraSerializableProperty.Invoke(helper, new object[] { view, prop }) as XtraSerializableProperty;
SerializablePropertyDescriptorPair p = new SerializablePropertyDescriptorPair(prop, newXtraSerializableProperty);
mi.Invoke(helper, new object[] { store, view, p, XtraSerializationFlags.None, null });
}
(view as IXtraSerializable).OnEndSerializing();
return store;
}
}
}