Ejemplo n.º 1
0
 public static string GetTypeNameForWindow(IPersistableWindow window)
 {
     try
     {
         Type windowType = window.GetType();
         return(registeredTypes.First(x => x.Value == windowType).Key);
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        private static XElement serializeWindow(IPersistableWindow window)
        {
            XElement xmlElement = new XElement(WINDOW_TAG);
            Type     windowType = window.GetType();

            string windowTypeName = WindowTypeRegister.GetTypeNameForWindow(window);

            if (windowTypeName == null)
            {
                return(null);
            }

            xmlElement.SetAttributeValue(WINDOW_ATTRIBUTE_TYPE, windowTypeName);

            Point pos = window.Position;

            xmlElement.SetAttributeValue(WINDOW_ATTRIBUTE_LEFT, pos.X);
            xmlElement.SetAttributeValue(WINDOW_ATTRIBUTE_TOP, pos.Y);

            Size size = window.Size;

            xmlElement.SetAttributeValue(WINDOW_ATTRIBUTE_WIDTH, size.Width);
            xmlElement.SetAttributeValue(WINDOW_ATTRIBUTE_HEIGHT, size.Height);

            foreach (var pair in window.GetKeyValuePairs())
            {
                XElement attributeElement = new XElement(ATTRIBUTE_TAG);
                attributeElement.SetAttributeValue(ATTRIBUTE_ATTRIBUTE_KEY, pair.Key);
                ValueConverter.SerializedData serialized = ValueConverter.Serialize(pair.Value);
                attributeElement.SetAttributeValue(ATTRIBUTE_ATTRIBUTE_VALUE, serialized.Value);
                if (serialized.TypeName != string.Empty)
                {
                    attributeElement.SetAttributeValue(ATTRIBUTE_ATTRIBUTE_TYPE, serialized.TypeName);
                }
                xmlElement.Add(attributeElement);
            }

            return(xmlElement);
        }