ConvertFrom() public method

public ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, object value ) : object
context ITypeDescriptorContext
culture System.Globalization.CultureInfo
value object
return object
Example #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var valueType = value.GetType();

            var originalValue = (Enum) value;
            var converter = new EnumConverter(valueType);
            var flag = (Enum) converter.ConvertFrom(parameter);

            Debug.Assert(flag != null, "flag != null");

            return originalValue.HasFlag(flag);
        }
Example #2
0
		public void ConvertFrom_Null ()
		{
			EnumConverter converter = new EnumConverter (typeof (E));
			try {
				converter.ConvertFrom (null, CultureInfo.InvariantCulture, null);
				Assert.Fail ("#1");
			} catch (NotSupportedException ex) {
				// EnumConverter cannot convert from (null)
				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.IsTrue (ex.Message.IndexOf (typeof (EnumConverter).Name) != -1, "#5");
				Assert.IsTrue (ex.Message.IndexOf ("(null)") != -1, "#6");
			}
		}
Example #3
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var booleanValue = (bool) value;

            var converter = new EnumConverter(targetType);
            var flag = (Enum)converter.ConvertFrom(parameter);

            if (booleanValue) {
                dynamic result = OriginalValue;
                result |= flag;
                return result;
            }
            else {
                dynamic result = OriginalValue;
                dynamic dynFlag = flag;
                result &= ~dynFlag;
                return result;
            }
        }
            private static FloatWindowStruct[] LoadFloatWindows(XmlTextReader xmlIn)
            {
                EnumConverter dockAlignmentConverter = new EnumConverter(typeof(DockAlignment));
                RectangleConverter rectConverter = new RectangleConverter();
                int countOfFloatWindows = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
                FloatWindowStruct[] floatWindows = new FloatWindowStruct[countOfFloatWindows];
                MoveToNextElement(xmlIn);
                for (int i = 0; i < countOfFloatWindows; i++)
                {
                    int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                    if (xmlIn.Name != "FloatWindow" || id != i)
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);

                    floatWindows[i].Bounds = (Rectangle)rectConverter.ConvertFromInvariantString(xmlIn.GetAttribute("Bounds"));
                    floatWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"), CultureInfo.InvariantCulture);
                    MoveToNextElement(xmlIn);
                    if (xmlIn.Name != "DockList" && xmlIn.Name != "NestedPanes")
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    int countOfNestedPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
                    floatWindows[i].NestedPanes = new NestedPane[countOfNestedPanes];
                    MoveToNextElement(xmlIn);
                    for (int j = 0; j < countOfNestedPanes; j++)
                    {
                        int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                        if (xmlIn.Name != "Pane" || id2 != j)
                            throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                        floatWindows[i].NestedPanes[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"), CultureInfo.InvariantCulture);
                        floatWindows[i].NestedPanes[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"), CultureInfo.InvariantCulture);
                        floatWindows[i].NestedPanes[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
                        floatWindows[i].NestedPanes[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
                        MoveToNextElement(xmlIn);
                    }
                }

                return floatWindows;
            }
            private static PaneStruct[] LoadPanes(XmlTextReader xmlIn)
            {
                EnumConverter dockStateConverter = new EnumConverter(typeof(DockState));
                int countOfPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
                PaneStruct[] panes = new PaneStruct[countOfPanes];
                MoveToNextElement(xmlIn);
                for (int i = 0; i < countOfPanes; i++)
                {
                    int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                    if (xmlIn.Name != "Pane" || id != i)
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);

                    panes[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
                    panes[i].IndexActiveContent = Convert.ToInt32(xmlIn.GetAttribute("ActiveContent"), CultureInfo.InvariantCulture);
                    panes[i].ZOrderIndex = -1;

                    MoveToNextElement(xmlIn);
                    if (xmlIn.Name != "Contents")
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    int countOfPaneContents = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
                    panes[i].IndexContents = new int[countOfPaneContents];
                    MoveToNextElement(xmlIn);
                    for (int j = 0; j < countOfPaneContents; j++)
                    {
                        int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                        if (xmlIn.Name != "Content" || id2 != j)
                            throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);

                        panes[i].IndexContents[j] = Convert.ToInt32(xmlIn.GetAttribute("RefID"), CultureInfo.InvariantCulture);
                        MoveToNextElement(xmlIn);
                    }
                }

                return panes;
            }
Example #6
0
		public static void LoadFromXml(DockPanel dockPanel, Stream stream, DeserializeDockContent deserializeContent)
		{

			if (dockPanel.Contents.Count != 0)
				throw new InvalidOperationException(ResourceHelper.GetString("DockPanel.LoadFromXml.AlreadyInitialized"));

			EnumConverter dockStateConverter = new EnumConverter(typeof(DockState));
			EnumConverter dockAlignmentConverter = new EnumConverter(typeof(DockAlignment));
			RectangleConverter rectConverter = new RectangleConverter();

			XmlTextReader xmlIn = new XmlTextReader(stream);
			xmlIn.WhitespaceHandling = WhitespaceHandling.None;
			xmlIn.MoveToContent();

			if (xmlIn.Name != "DockPanel")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

			string formatVersion = xmlIn.GetAttribute("FormatVersion");
			if (formatVersion != ConfigFileVersion)
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidFormatVersion"));
			DockPanelStruct dockPanelStruct = new DockPanelStruct();
			dockPanelStruct.DockLeftPortion = Convert.ToDouble(xmlIn.GetAttribute("DockLeftPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.DockRightPortion = Convert.ToDouble(xmlIn.GetAttribute("DockRightPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.DockTopPortion = Convert.ToDouble(xmlIn.GetAttribute("DockTopPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.DockBottomPortion = Convert.ToDouble(xmlIn.GetAttribute("DockBottomPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.IndexActiveDocumentPane = Convert.ToInt32(xmlIn.GetAttribute("ActiveDocumentPane"));
			dockPanelStruct.IndexActivePane = Convert.ToInt32(xmlIn.GetAttribute("ActivePane"));

			// Load Contents
			MoveToNextElement(xmlIn);
			if (xmlIn.Name != "Contents")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfContents = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			ContentStruct[] contents = new ContentStruct[countOfContents];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfContents; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "Content" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				contents[i].PersistString = xmlIn.GetAttribute("PersistString");
				contents[i].AutoHidePortion = Convert.ToDouble(xmlIn.GetAttribute("AutoHidePortion"), CultureInfo.InvariantCulture);
				contents[i].IsHidden = Convert.ToBoolean(xmlIn.GetAttribute("IsHidden"));
				contents[i].IsFloat = Convert.ToBoolean(xmlIn.GetAttribute("IsFloat"));
				MoveToNextElement(xmlIn);
			}

			// Load Panes
			if (xmlIn.Name != "Panes")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			PaneStruct[] panes = new PaneStruct[countOfPanes];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfPanes; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "Pane" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				panes[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
				panes[i].IndexActiveContent = Convert.ToInt32(xmlIn.GetAttribute("ActiveContent"));
				panes[i].ZOrderIndex = -1;

				MoveToNextElement(xmlIn);
				if (xmlIn.Name != "Contents")
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
				int countOfPaneContents = Convert.ToInt32(xmlIn.GetAttribute("Count"));
				panes[i].IndexContents = new int[countOfPaneContents];
				MoveToNextElement(xmlIn);
				for (int j=0; j<countOfPaneContents; j++)
				{
					int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"));
					if (xmlIn.Name != "Content" || id2 != j)
						throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

					panes[i].IndexContents[j] = Convert.ToInt32(xmlIn.GetAttribute("RefID"));
					MoveToNextElement(xmlIn);
				}
			}

			// Load DockWindows
			if (xmlIn.Name != "DockWindows")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfDockWindows = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			DockWindowStruct[] dockWindows = new DockWindowStruct[countOfDockWindows];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfDockWindows; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "DockWindow" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				dockWindows[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
				dockWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"));
				MoveToNextElement(xmlIn);
				if (xmlIn.Name != "DockList")
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
				int countOfDockList = Convert.ToInt32(xmlIn.GetAttribute("Count"));
				dockWindows[i].DockList = new DockListItem[countOfDockList];
				MoveToNextElement(xmlIn);
				for (int j=0; j<countOfDockList; j++)
				{
					int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"));
					if (xmlIn.Name != "Pane" || id2 != j)
						throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
					dockWindows[i].DockList[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"));
					dockWindows[i].DockList[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"));
					dockWindows[i].DockList[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
					dockWindows[i].DockList[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
					MoveToNextElement(xmlIn);
				}
			}

			// Load FloatWindows
			if (xmlIn.Name != "FloatWindows")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfFloatWindows = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			FloatWindowStruct[] floatWindows = new FloatWindowStruct[countOfFloatWindows];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfFloatWindows; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "FloatWindow" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				floatWindows[i].Bounds = (Rectangle)rectConverter.ConvertFromInvariantString(xmlIn.GetAttribute("Bounds"));
				floatWindows[i].AllowRedocking = Convert.ToBoolean(xmlIn.GetAttribute("AllowRedocking"));
				floatWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"));
				MoveToNextElement(xmlIn);
				if (xmlIn.Name != "DockList")
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
				int countOfDockList = Convert.ToInt32(xmlIn.GetAttribute("Count"));
				floatWindows[i].DockList = new DockListItem[countOfDockList];
				MoveToNextElement(xmlIn);
				for (int j=0; j<countOfDockList; j++)
				{
					int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"));
					if (xmlIn.Name != "Pane" || id2 != j)
						throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
					floatWindows[i].DockList[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"));
					floatWindows[i].DockList[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"));
					floatWindows[i].DockList[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
					floatWindows[i].DockList[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
					MoveToNextElement(xmlIn);
				}
			}
			xmlIn.Close();
					
			dockPanel.DockLeftPortion = dockPanelStruct.DockLeftPortion;
			dockPanel.DockRightPortion = dockPanelStruct.DockRightPortion;
			dockPanel.DockTopPortion = dockPanelStruct.DockTopPortion;
			dockPanel.DockBottomPortion = dockPanelStruct.DockBottomPortion;

			// Create Contents
			for (int i=0; i<contents.Length; i++)
			{
				DockContent content = deserializeContent(contents[i].PersistString);
				if (content == null)
					content = new DummyContent();
				content.DockPanel = dockPanel;
				content.AutoHidePortion = contents[i].AutoHidePortion;
				content.IsHidden = true;
				content.IsFloat = contents[i].IsFloat;
			}

			// Create panes
			for (int i=0; i<panes.Length; i++)
			{
				DockPane pane = null;
				for (int j=0; j<panes[i].IndexContents.Length; j++)
				{
					DockContent content = dockPanel.Contents[panes[i].IndexContents[j]];
					if (j==0)
						pane = dockPanel.DockPaneFactory.CreateDockPane(content, panes[i].DockState, false);
					else if (panes[i].DockState == DockState.Float)
						content.FloatPane = pane;
					else
						content.PanelPane = pane;
				}
			}

			// Assign Panes to DockWindows
			for (int i=0; i<dockWindows.Length; i++)
			{
				for (int j=0; j<dockWindows[i].DockList.Length; j++)
				{
					DockWindow dw = dockPanel.DockWindows[dockWindows[i].DockState];
					int indexPane = dockWindows[i].DockList[j].IndexPane;
					DockPane pane = dockPanel.Panes[indexPane];
					int indexPrevPane = dockWindows[i].DockList[j].IndexPrevPane;
					DockPane prevPane = (indexPrevPane == -1) ? dw.DockList.GetDefaultPrevPane(pane) : dockPanel.Panes[indexPrevPane];
					DockAlignment alignment = dockWindows[i].DockList[j].Alignment;
					double proportion = dockWindows[i].DockList[j].Proportion;
					pane.AddToDockList(dw, prevPane, alignment, proportion);
					if (panes[indexPane].DockState == dw.DockState)
						panes[indexPane].ZOrderIndex = dockWindows[i].ZOrderIndex;
				}
			}

			// Create float windows
			for (int i=0; i<floatWindows.Length; i++)
			{
				FloatWindow fw = null;
				for (int j=0; j<floatWindows[i].DockList.Length; j++)
				{
					int indexPane = floatWindows[i].DockList[j].IndexPane;
					DockPane pane = dockPanel.Panes[indexPane];
					if (j == 0)
						fw = dockPanel.FloatWindowFactory.CreateFloatWindow(dockPanel, pane, floatWindows[i].Bounds);
					else
					{
						int indexPrevPane = floatWindows[i].DockList[j].IndexPrevPane;
						DockPane prevPane = indexPrevPane == -1 ? null : dockPanel.Panes[indexPrevPane];
						DockAlignment alignment = floatWindows[i].DockList[j].Alignment;
						double proportion = floatWindows[i].DockList[j].Proportion;
						pane.AddToDockList(fw, prevPane, alignment, proportion);
						if (panes[indexPane].DockState == fw.DockState)
							panes[indexPane].ZOrderIndex = floatWindows[i].ZOrderIndex;
					}
				}
			}

			// sort DockContent by its Pane's ZOrder
			int[] sortedContents = null;
			if (contents.Length > 0)
			{
				sortedContents = new int[contents.Length];
				for (int i=0; i<contents.Length; i++)
					sortedContents[i] = i;

				int lastDocument = contents.Length;
				for (int i=0; i<contents.Length - 1; i++)
				{
					for (int j=i+1; j<contents.Length; j++)
					{
						DockPane pane1 = dockPanel.Contents[sortedContents[i]].Pane;
						int ZOrderIndex1 = pane1 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane1)].ZOrderIndex;
						DockPane pane2 = dockPanel.Contents[sortedContents[j]].Pane;
						int ZOrderIndex2 = pane2 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane2)].ZOrderIndex;
						if (ZOrderIndex1 > ZOrderIndex2)
						{
							int temp = sortedContents[i];
							sortedContents[i] = sortedContents[j];
							sortedContents[j] = temp;
						}
					}
				}
			}

			// show non-document DockContent first to avoid screen flickers
			for (int i=0; i<contents.Length; i++)
			{
				DockContent content = dockPanel.Contents[sortedContents[i]];
				if (content.Pane != null && content.Pane.DockState != DockState.Document)
					content.IsHidden = contents[sortedContents[i]].IsHidden;
			}

			// after all non-document DockContent, show document DockContent
			for (int i=0; i<contents.Length; i++)
			{
				DockContent content = dockPanel.Contents[sortedContents[i]];
				if (content.Pane != null && content.Pane.DockState == DockState.Document)
					content.IsHidden = contents[sortedContents[i]].IsHidden;
			}

			for (int i=0; i<panes.Length; i++)
				dockPanel.Panes[i].ActiveContent = panes[i].IndexActiveContent == -1 ? null : dockPanel.Contents[panes[i].IndexActiveContent];

			if (dockPanelStruct.IndexActiveDocumentPane != -1)
				dockPanel.Panes[dockPanelStruct.IndexActiveDocumentPane].Activate();

			if (dockPanelStruct.IndexActivePane != -1)
				dockPanel.Panes[dockPanelStruct.IndexActivePane].Activate();

			for (int i=dockPanel.Contents.Count-1; i>=0; i--)
				if (dockPanel.Contents[i] is DummyContent)
					dockPanel.Contents[i].Close();
		}
Example #7
0
            private static DockWindowStruct[] LoadDockWindows(XmlTextReader xmlIn, DockPanel dockPanel)
            {
                EnumConverter dockStateConverter = new EnumConverter(typeof(DockState));
                EnumConverter dockAlignmentConverter = new EnumConverter(typeof(DockAlignment));
                int countOfDockWindows = dockPanel.DockWindows.Count;
                DockWindowStruct[] dockWindows = new DockWindowStruct[countOfDockWindows];
                MoveToNextElement(xmlIn);
                for (int i = 0; i < countOfDockWindows; i++)
                {
                    int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                    if (xmlIn.Name != "DockWindow" || id != i)
                        throw new ArgumentException(DockPanelSuite.Properties.Resources.DockPanel_LoadFromXml_InvalidXmlFormat);

                    dockWindows[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
                    dockWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"), CultureInfo.InvariantCulture);
                    MoveToNextElement(xmlIn);
                    if (xmlIn.Name != "DockList" && xmlIn.Name != "NestedPanes")
                        throw new ArgumentException(DockPanelSuite.Properties.Resources.DockPanel_LoadFromXml_InvalidXmlFormat);
                    int countOfNestedPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
                    dockWindows[i].NestedPanes = new NestedPane[countOfNestedPanes];
                    MoveToNextElement(xmlIn);
                    for (int j = 0; j < countOfNestedPanes; j++)
                    {
                        int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                        if (xmlIn.Name != "Pane" || id2 != j)
                            throw new ArgumentException(DockPanelSuite.Properties.Resources.DockPanel_LoadFromXml_InvalidXmlFormat);
                        dockWindows[i].NestedPanes[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"), CultureInfo.InvariantCulture);
                        dockWindows[i].NestedPanes[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"), CultureInfo.InvariantCulture);
                        dockWindows[i].NestedPanes[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
                        dockWindows[i].NestedPanes[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
                        MoveToNextElement(xmlIn);
                    }
                }

                return dockWindows;
            }
Example #8
0
		public void ConvertFrom_String ()
		{
			EnumConverter converter = new EnumConverter (typeof (E));
			Assert.AreEqual (E.Bb, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "Bb"), "#A1");
			Assert.AreEqual (E.Cc, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "2"), "#A2");
			Assert.AreEqual (E.Bb, converter.ConvertFrom (null, CultureInfo.InvariantCulture, " Bb "), "#A3");
			Assert.AreEqual (E.Dd, converter.ConvertFrom (null, CultureInfo.InvariantCulture, " 3 "), "#A4");
			Assert.AreEqual ((E) 666, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "666"), "#A5");
			Assert.AreEqual (E.Dd, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "Bb,Dd"), "#A6");
			Assert.AreEqual (E.Dd, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "Dd,Bb"), "#A7");
			Assert.AreEqual (E.Bb, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "Aa,Bb"), "#A8");

			try {
				converter.ConvertFrom (null, CultureInfo.InvariantCulture, string.Empty);
				Assert.Fail ("#B1");
#if NET_2_0
			} catch (FormatException ex) {
				//  is not a valid value for E
				Assert.AreEqual (typeof (FormatException), ex.GetType (), "#B2");
				Assert.IsNotNull (ex.InnerException, "#B3");
				Assert.AreEqual (typeof (ArgumentException), ex.InnerException.GetType (), "#B4");
				Assert.IsNotNull (ex.Message, "#B5");
				Assert.IsTrue (ex.Message.IndexOf ("E") != -1, "#B6");

				// Must specify valid information for parsing in the string
				ArgumentException inner = (ArgumentException) ex.InnerException;
				Assert.IsNull (inner.InnerException, "#B7");
				Assert.IsNotNull (inner.Message, "#B8");
			}
#else
			} catch (ArgumentException ex) {
Example #9
0
		public void ConvertFrom_EnumArray ()
		{
			EnumConverter converter = new EnumConverter (typeof (E));
			Assert.AreEqual (E.Aa, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [] { E.Aa }), "#A1");
			Assert.AreEqual ((E) 8, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [] { E.Aa, E2.Dd }), "#A2");
			Assert.AreEqual ((E) 958, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [] { (E2) 444, (E) 666 }), "#A3");
			Assert.AreEqual ((E) 0, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [0]), "#A4");

			converter = new EnumConverter (typeof (E2));
			Assert.AreEqual ((E2) 0, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [] { E.Aa }), "#B1");
			Assert.AreEqual (E2.Dd, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [] { E.Aa, E2.Dd }), "#B2");
			Assert.AreEqual ((E2) 958, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [] { (E2) 444, (E) 666 }), "#B3");
			Assert.AreEqual ((E2) 0, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [0]), "#B4");
			Assert.AreEqual (E2.Bb | E2.Dd, converter.ConvertFrom (null,
				CultureInfo.InvariantCulture,
				(Enum []) new Enum [] { E2.Bb, E2.Dd }), "#B5");
		}
Example #10
0
 /// <summary>
 /// Parse WindowState.
 /// </summary>
 /// <param name="xmlIn"></param>
 /// <returns></returns>
 private static WindowStateStruct LoadWindowState(XmlTextReader xmlIn)
 {
     while (!xmlIn.Name.Equals("Form"))
     {
         if (!MoveToNextElement(xmlIn))
             throw new ArgumentException();
     }
     EnumConverter windowStateConverter = new EnumConverter(typeof(FormWindowState));
     WindowStateStruct windowState = new WindowStateStruct();
     windowState.WindowState = (FormWindowState)windowStateConverter.ConvertFrom(xmlIn.GetAttribute("WindowState"));
     windowState.Left = Convert.ToInt32(xmlIn.GetAttribute("Left"), CultureInfo.InvariantCulture);
     windowState.Top = Convert.ToInt32(xmlIn.GetAttribute("Top"), CultureInfo.InvariantCulture);
     windowState.Height = Convert.ToInt32(xmlIn.GetAttribute("Height"), CultureInfo.InvariantCulture);
     windowState.Width = Convert.ToInt32(xmlIn.GetAttribute("Width"), CultureInfo.InvariantCulture);
     windowState.Screen = Convert.ToInt32(xmlIn.GetAttribute("Screen"), CultureInfo.InvariantCulture);
     return windowState;
 }
Example #11
0
        // Writes either Binary or the type converted binary.
        // Things like boolean, enum, strings, and DPs can be type since they aren't thread affine
        private bool WriteTypeConvertedInstance(short converterId, int dataByteSize) 
        {
            TypeConverter converter; 
            switch (converterId) 
            {
                case Baml2006SchemaContext.KnownTypes.XamlInt32CollectionSerializer: 
                    _xamlNodesWriter.WriteValue(GetInt32Collection());
                    break;
                case Baml2006SchemaContext.KnownTypes.EnumConverter:
                    converter = new EnumConverter(_context.CurrentFrame.XamlType.UnderlyingType); 
                    _xamlNodesWriter.WriteValue(converter.ConvertFrom(_binaryReader.ReadBytes(dataByteSize)));
                    break; 
                case Baml2006SchemaContext.KnownTypes.BooleanConverter: 
                    Debug.Assert(dataByteSize == 1);
                    _xamlNodesWriter.WriteValue((_binaryReader.ReadBytes(1)[0] == 0) ? false : true); 
                    break;
                case Baml2006SchemaContext.KnownTypes.StringConverter:
                    _xamlNodesWriter.WriteValue(_binaryReader.ReadString());
                    break; 
                case Baml2006SchemaContext.KnownTypes.DependencyPropertyConverter:
                    DependencyProperty property = null; 
                    if (dataByteSize == 2) 
                    {
                        property = BamlSchemaContext.GetDependencyProperty(_binaryReader.ReadInt16()); 
                    }
                    else
                    {
                        Type type = BamlSchemaContext.GetXamlType(_binaryReader.ReadInt16()).UnderlyingType; 
                        property = DependencyProperty.FromName(_binaryReader.ReadString(), type);
                    } 
                    _xamlNodesWriter.WriteValue(property); 
                    break;
                case Baml2006SchemaContext.KnownTypes.XamlBrushSerializer: 
                case Baml2006SchemaContext.KnownTypes.XamlPathDataSerializer:
                case Baml2006SchemaContext.KnownTypes.XamlPoint3DCollectionSerializer:
                case Baml2006SchemaContext.KnownTypes.XamlPointCollectionSerializer:
                case Baml2006SchemaContext.KnownTypes.XamlVector3DCollectionSerializer: 
                    DeferredBinaryDeserializerExtension deserializerME = new DeferredBinaryDeserializerExtension(this, _binaryReader, converterId, dataByteSize);
                    _xamlNodesWriter.WriteValue(deserializerME); 
                    break; 
                default:
                    throw new NotImplementedException(); 
            }

            return true;
        } 
Example #12
0
		public void ConvertFrom_String_Flags ()
		{
			EnumConverter converter = new EnumConverter (typeof (E2));
			Assert.AreEqual (E2.Cc, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "Cc"), "#B1");
			Assert.AreEqual (E2.Dd, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "8"), "#B2");
			Assert.AreEqual (E2.Cc | E2.Dd, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "Cc,Dd"), "#B3");
			Assert.AreEqual (E2.Aa | E2.Bb, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "3"), "#B4");
			Assert.AreEqual (E2.Bb | E2.Cc, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "2,4"), "#B5");
			Assert.AreEqual (E2.Aa | E2.Dd, converter.ConvertFrom (null, CultureInfo.InvariantCulture, " 1 , 8 "), "#B5");
			Assert.AreEqual ((E2) 666, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "666"), "#B6");
			Assert.AreEqual (E2.Cc | E2.Dd, converter.ConvertFrom (null, CultureInfo.InvariantCulture, " Dd , Cc "), "#B7");
			Assert.AreEqual (E2.Bb, converter.ConvertFrom (null, CultureInfo.InvariantCulture, " Bb "), "#B8");
			Assert.AreEqual (E2.Aa | E2.Bb, converter.ConvertFrom (null, CultureInfo.InvariantCulture, " 3 "), "#B9");

			try {
				converter.ConvertFrom (null, CultureInfo.InvariantCulture, string.Empty);
				Assert.Fail ("#B1");
			} catch (FormatException ex) {
				//  is not a valid value for E2
				Assert.AreEqual (typeof (FormatException), ex.GetType (), "#B2");
				Assert.IsNotNull (ex.InnerException, "#B3");
				Assert.AreEqual (typeof (ArgumentException), ex.InnerException.GetType (), "#B4");
				Assert.IsNotNull (ex.Message, "#B5");
				Assert.IsTrue (ex.Message.IndexOf ("E2") != -1, "#B6");

				// Must specify valid information for parsing in the string
				ArgumentException inner = (ArgumentException) ex.InnerException;
				Assert.IsNull (inner.InnerException, "#B7");
				Assert.IsNotNull (inner.Message, "#B8");
			}

			try {
				converter.ConvertFrom (null, CultureInfo.InvariantCulture, "Aa Bb");
				Assert.Fail ("#C1");
			} catch (FormatException ex) {
				// Aa Bb is not a valid value for E2
				Assert.AreEqual (typeof (FormatException), ex.GetType (), "#C2");
				Assert.IsNotNull (ex.InnerException, "#C3");
				Assert.AreEqual (typeof (ArgumentException), ex.InnerException.GetType (), "#C4");
				Assert.IsNotNull (ex.Message, "#C5");
				Assert.IsTrue (ex.Message.IndexOf ("Aa Bb") != -1, "#C6");
				Assert.IsTrue (ex.Message.IndexOf ("E2") != -1, "#C7");

				// Requested value Aa Bb was not found
				ArgumentException inner = (ArgumentException) ex.InnerException;
				Assert.IsNotNull (inner.Message, "#C9");
				Assert.IsTrue (inner.Message.IndexOf ("Aa Bb") != -1, "#C10");
				Assert.IsNull (inner.ParamName, "#C11");
			}

			try {
				converter.ConvertFrom (null, CultureInfo.InvariantCulture, "2,");
				Assert.Fail ("#D1");
			} catch (FormatException ex) {
				// 2, is not a valid value for E2
				Assert.AreEqual (typeof (FormatException), ex.GetType (), "#D2");
				Assert.IsNotNull (ex.InnerException, "#D3");
				Assert.AreEqual (typeof (ArgumentException), ex.InnerException.GetType (), "#D4");
				Assert.IsNotNull (ex.Message, "#D5");
				Assert.IsTrue (ex.Message.IndexOf ("2,") != -1, "#D6");
				Assert.IsTrue (ex.Message.IndexOf ("E2") != -1, "#D7");

				// Must specify valid information for parsing in the string
				ArgumentException inner = (ArgumentException) ex.InnerException;
				Assert.IsNull (inner.InnerException, "#D8");
				Assert.IsNotNull (inner.Message, "#D9");
				Assert.IsFalse (inner.Message.IndexOf ("2,") != -1, "#D10");
			}
		}