Exemplo n.º 1
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");
        }
Exemplo n.º 2
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) {
Exemplo n.º 3
0
            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;
            }
Exemplo n.º 4
0
    /// <summary>
    /// Transforms DataRow into business object.
    /// </summary>
    /// <typeparam name="TEntity">A type that inherits EntityBase.</typeparam>
    /// <typeparam name="TDataRow">A type that inherits DataRow.</typeparam>
    /// <param name="dataRow">DataRow object which is transformed from business object.</param>
    /// <param name="entity">business object which is transformed into DataRow object.</param>
    public static void TransformDataRowToEntity <TEntity, TDataRow>(ref TDataRow dataRow, ref TEntity entity)
        where TDataRow : DataRow
        where TEntity : EntityBase
    {
        IQueryable <DataField> entityFields = entity.GetDataFields();

        foreach (var entityField in entityFields)
        {
            if (dataRow[entityField.DataFieldMapping.MappedField] is System.DBNull)
            {
                entityField.Property.SetValue(entity, null, null);
            }
            else
            {
                if (entityField.Property.GetType().IsEnum)
                {
                    Type          enumType      = entityField.Property.GetType();
                    EnumConverter enumConverter = new EnumConverter(enumType);
                    object        enumValue     = enumConverter.ConvertFrom(dataRow[entityField.DataFieldMapping.MappedField]);
                    entityField.Property.SetValue(entity, enumValue, null);
                }
                else
                {
                    entityField.Property.SetValue(entity, dataRow[entityField.DataFieldMapping.MappedField], null);
                }
            }
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Helper method for converting from a string to an enum using a converter.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="culture">The culture to use to read the localized strings</param>
        /// <returns></returns>
        public static Nullable <T> ConvertFromType <T>(string value, CultureInfo culture)
            where T : struct
        {
            Nullable <T> returnValue = new Nullable <T>();

            returnValue = returnValue.GetValueOrDefault();

            if (value == null)
            {
                return(returnValue);
            }

            EnumConverter converter = GetEnumConverter <T>();

            if (converter == null)
            {
                return(returnValue);
            }

            if (converter.CanConvertFrom(value.GetType()))
            {
                object converted = converter.ConvertFrom(null, culture, value);

                if (converted != null && (converted is T))
                {
                    returnValue = (T)converted;
                }
            }

            return(returnValue);
        }
Exemplo n.º 6
0
        private void cboActionType_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedAction = ActionTypes.Highlight;
            var ec             = new EnumConverter(selectedAction.GetType());

            _action.ActionType = (ActionTypes)ec.ConvertFrom(cboActionType.Text);
            populateControls();
        }
Exemplo n.º 7
0
        public static void ConvertFrom_LongFlagsEnum_String()
        {
            EnumConverter converter = new EnumConverter(typeof(LongFlagsEnum));
            string        str       = $"{LongFlagsEnum.Bit62}, {LongFlagsEnum.Bit63}";
            LongFlagsEnum result    = (LongFlagsEnum)converter.ConvertFrom(null, null, str);

            Assert.Equal(LongFlagsEnum.Bit62 | LongFlagsEnum.Bit63, result);
        }
Exemplo n.º 8
0
        public static void ConvertFrom_LongFlagsEnum_EnumArray()
        {
            EnumConverter converter = new EnumConverter(typeof(LongFlagsEnum));

            Enum[]        arr    = new Enum[] { LongFlagsEnum.Bit62, LongFlagsEnum.Bit63 };
            LongFlagsEnum result = (LongFlagsEnum)converter.ConvertFrom(null, null, arr);

            Assert.Equal(LongFlagsEnum.Bit62 | LongFlagsEnum.Bit63, result);
        }
Exemplo n.º 9
0
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (parameter != null)
     {
         EnumConverter conv  = new EnumConverter(typeof(ReportsSubviewType));
         object        param = conv.ConvertFrom(parameter);
         return(value.Equals(param) ? Visibility.Visible : Visibility.Collapsed);
     }
     return(value.Equals(ReportsSubviewType.SavedReports) ? Visibility.Collapsed : Visibility.Visible);
 }
Exemplo n.º 10
0
        public static void ConvertFromInt32()
        {
            // Arrange
            var converter = new EnumConverter(typeof(Answer));

            // Act
            var result = converter.ConvertFrom(1);

            // Assert
            Assert.Equal(Answer.Yes, result);
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
0
 /// <summary>
 /// Retourne la valeur.
 /// </summary>
 /// <param name="serviceProvider">objet fournissant des services au markup</param>
 /// <returns>
 /// La valeur.
 /// </returns>
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     if (EnumType != null)
     {
         var typeConverter = new EnumConverter(EnumType);
         return(typeConverter.ConvertFrom(this.EnumValue));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 13
0
            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);
                    }

                    var convertFromInvariantString = rectConverter.ConvertFromInvariantString(xmlIn.GetAttribute("Bounds"));
                    if (convertFromInvariantString != null)
                    {
                        floatWindows[i].Bounds = (Rectangle)convertFromInvariantString;
                    }
                    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);
                        var convertFrom = dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
                        if (convertFrom != null)
                        {
                            floatWindows[i].NestedPanes[j].Alignment = (DockAlignment)convertFrom;
                        }
                        floatWindows[i].NestedPanes[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
                        MoveToNextElement(xmlIn);
                    }
                }

                return(floatWindows);
            }
Exemplo n.º 14
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(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    }

                    var @from = dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
                    if (@from != null)
                    {
                        dockWindows[i].DockState = (DockState)@from;
                    }
                    dockWindows[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);
                    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(Strings.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);
                        var convertFrom = dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
                        if (convertFrom != null)
                        {
                            dockWindows[i].NestedPanes[j].Alignment = (DockAlignment)convertFrom;
                        }
                        dockWindows[i].NestedPanes[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
                        MoveToNextElement(xmlIn);
                    }
                }

                return(dockWindows);
            }
Exemplo n.º 15
0
        public static T FlagAdd <T>(this T src, T value) where T : struct
        {
            CheckEnumIsFlags <T>();


            var srcvalue = Convert.ToInt32(src);
            var desvalue = Convert.ToInt32(value);

            var ret = srcvalue | desvalue;

            var ec = new EnumConverter(typeof(T));

            return((T)ec.ConvertFrom(ret));
        }
Exemplo n.º 16
0
        private DockTreeZOrder FromString(string s)
        {
            Dock first, second, third, fourth;

            string[] strings = s.Split(',');

            if (strings.Length != 4)
            {
                throw GetConvertFromException(s);
            }

            first  = (Dock)s_dockConverter.ConvertFrom(strings[0].Trim());
            second = (Dock)s_dockConverter.ConvertFrom(strings[1].Trim());
            third  = (Dock)s_dockConverter.ConvertFrom(strings[2].Trim());
            fourth = (Dock)s_dockConverter.ConvertFrom(strings[3].Trim());

            if (!DockTreeZOrder.CheckValues(first, second, third, fourth))
            {
                throw GetConvertFromException(s);
            }

            return(new DockTreeZOrder(first, second, third, fourth));
        }
Exemplo n.º 17
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");
            }
        }
Exemplo n.º 18
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (cmbKeys.SelectedItem != null)
     {
         EnumConverter ec = new EnumConverter(typeof(Keys));
         hotkey.ModKey = GetModKey();
         hotkey.Key    = (Keys)ec.ConvertFrom(cmbKeys.SelectedItem);
         //hotkey.Key = (Keys)cmbKeys.SelectedItem;
     }
     else
     {
         hotkey.ModKey = ModKeys.None;
         hotkey.Key    = Keys.None;
     }
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
        public void Raise(object parameter)
        {
            WindowRequestAction action;

            if (parameter is WindowRequestAction)
            {
                action = (WindowRequestAction)parameter;
            }
            else
            {
                var enumConverter = new EnumConverter(typeof(WindowRequestAction));
                var value         = enumConverter.ConvertFrom(parameter);
                if (value == null)
                {
                    return;
                }

                action = (WindowRequestAction)value;
            }
            Raise(action);
        }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
0
        private static T ConvertValue <T>(object value)
        {
            if (value == null)
            {
                return(default(T));
            }

            object objectValue = value;

            if (value is PSObject)
            {
                objectValue = ((PSObject)value).BaseObject;
            }

            if (typeof(T).IsEnum)
            {
                EnumConverter ec = new EnumConverter(typeof(T));
                objectValue = ec.ConvertFrom(value);
            }

            return((T)objectValue);
        }
Exemplo n.º 22
0
 private T Convert <T>(T origin, IFormatProvider provider, out RedisValue redisVal)
 {
     redisVal = EnumConverter.ConvertTo(origin, typeof(T), provider);
     return((T)EnumConverter.ConvertFrom(redisVal, typeof(T), provider));
 }
Exemplo n.º 23
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");
            }
        }
Exemplo n.º 24
0
		/// <summary>
		/// The public constructor requires the calling routine to supply the
		/// values of a label row and the corresponding details in the form of a
		/// pair of well-formed TAB delimited strings.
		/// </summary>
		/// <param name="pstrParameterInfoDetail">
		/// Supply a TAB delimited string that contains a field (column) for
		/// each property named in the pastrParameterInfoColumnNames string.
		/// </param>
		/// <param name="pastrParameterInfoColumnNames">
		/// Specify a TAB delimited string that names the columns (properties)
		/// of the parameter that are specified in the pstrParameterInfoDetail
		/// string that accompanies it.
		/// 
		/// This parameter is processed once only, the first time an application
		/// calls the constructor. The string is parsed into a static array of
		/// strings that is visible to all instances in the application. Though
		/// subsequent instances may supply the same or different values, even a
		/// null reference or the empty string, subsequent constructions ignore
		/// this parameter, since the object knows that it is already populated.
		/// 
		/// Currently, only two properties are supported.
		/// 
		/// 1) InternalName is the name by which the parameter is identified by
		/// the code; it is expected to correspond to the name of a command line
		/// argument, application setting, or both. Instances do not verify that
		/// InternalName values are unique; that is the responsbility of the
		/// calling routine.
		/// 
		/// 2) ParamType is expected to correspond to a valid value of generic
		/// type T. Values are parsed, and invalid values cause an exception to
		/// be thrown, since such an error is the result of a misconfigured or
		/// corrupted application installation.
		/// 
		/// InternalName and ParamType may be specified in any order, so long as
		/// the order is consistent across all instances.
		/// </param>
		public ParameterTypeInfo (
			string pstrParameterInfoDetail ,
			string pastrParameterInfoColumnNames )
		{
			if ( s_astrParameterNames == null )
			{   // Perform this expensive operation once only.
				s_astrParameterNames = s_parser.Parse ( pastrParameterInfoColumnNames );
			}   // if ( s_astrParameterNames == null )

			string [ ] astrParameterTypeInfo = s_parser.Parse ( pstrParameterInfoDetail );

			if ( astrParameterTypeInfo.Length == s_astrParameterNames.Length )
			{
				for ( int intPosition = ArrayInfo.ARRAY_FIRST_ELEMENT ;
					      intPosition < astrParameterTypeInfo.Length ;
						  intPosition++ )
				{
					switch ( s_astrParameterNames [ intPosition ] )
					{
						case @"InternalName":
							_strParameterName = astrParameterTypeInfo [ intPosition ];
							break;
						case @"ParamType":
							EnumConverter enumConverter = new EnumConverter ( _enmParameterType.GetType ( ) );

							//	------------------------------------------------
							//	Private member _enmParameterType corresponds to
							//	the public ParameterType property, which is an
							//	enumeration of generic type T, which must be a
							//	valid Microsoft .NET Enum type. The ConvertFrom
							//	method either parses a test string into a valid
							//	Enum value of the type that was specified to the
							//	constructor, or throws a FormatException 
							//	exception, which is caught and wrapped in a new
							//	InvalidOperationException exception, which is
							//	thrown to the calling routine.
							//	------------------------------------------------

							try
							{   // Catching the FormatException exception here permits augmenting the message with contextual details that would otherwise be lost.
								_enmParameterType = ( T ) enumConverter.ConvertFrom ( astrParameterTypeInfo [ intPosition ] );
							}
							catch ( FormatException formatException )
							{   // The catch block bounds the scope of this strMessage.
								string strMessage = string.Format (									// Prepare a detailed diagnostic message.
									Properties.Resources.MESSAGE_INVALID_PARAMETER_TYPE_VALUE ,     // Format Control String
									formatException.Message ,                                       // Format Item 0: {0}{4}
									s_astrParameterNames [ intPosition ] ,                          // Format Item 1: Column Name  = {1}{4}
									intPosition ,                                                   // Format Item 2: Column Index = {2}{4}
									pstrParameterInfoDetail ,                                       // Format Item 3: Whole Record = {3}{4}
									Environment.NewLine );                                          // Format Item 4: Platform-dependent newline.
								throw new InvalidOperationException (
									strMessage ,
									formatException );
							}   // catch ( FormatException formatException )
							break;  // case @"ParamType":
						default:
							{   // Bound the scope of this strMessage.
								string strMessage = string.Format (
									Properties.Resources.ERRMSG_INTERNAL_PROCESSING_ERROR_004 ,
									s_astrParameterNames [ intPosition ] ,
									Environment.NewLine );
								throw new InvalidOperationException ( strMessage );
							}   // Make this strMessage disappear.
					}   // switch ( s_astrParameterNames [ intPosition ] )
				}   // for ( int intPosition = ArrayInfo.ARRAY_FIRST_ELEMENT ; intPosition < astrParameterTypeInfo.Length ; intPosition++ )
			}   // TRUE (anticipated outcome) block, if ( astrParameterTypeInfo.Length == s_astrParameterNames.Length )
			else
			{   // Toss cookies and fall over dead. The ELSE block bounds the scope of this strMessage.
				string strMessage = string.Format ( 
					Properties.Resources.ERRMSG_INTERNAL_PROCESSING_ERROR_002 ,	// Format Control String
					s_astrParameterNames.Length ,                               // Format Item 0: Expected field count = {0}
					astrParameterTypeInfo.Length ,                              // Format Item 1: Actual field count   = {1}
					pstrParameterInfoDetail ,                                   // Format Item 2: Actual detail record = {2}
					Environment.NewLine );                                      // Format Item 3: Platform-dependent newline sequence
				throw new InvalidOperationException ( strMessage );
			}   // FALSE (unanticipated outcome) block, if ( astrParameterTypeInfo.Length == s_astrParameterNames.Length )
		}   // ParameterTypeInfo constructor for first or subsequent detail item
Exemplo n.º 25
0
        public static void LoadFromXml(DockContainer dockPanel, Stream stream, DeserializeDockContent deserializeContent, bool closeStream)
        {
            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();

            while (!xmlIn.Name.Equals("DockPanel"))
            {
                if (!MoveToNextElement(xmlIn))
                {
                    throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
                }
            }

            string formatVersion = xmlIn.GetAttribute("FormatVersion");

            if (!IsFormatVersionValid(formatVersion))
            {
                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 = dockPanel.DockWindows.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);
                }
            }

            if (closeStream)
            {
                xmlIn.Close();
            }

            dockPanel.DockLeftPortion   = dockPanelStruct.DockLeftPortion;
            dockPanel.DockRightPortion  = dockPanelStruct.DockRightPortion;
            dockPanel.DockTopPortion    = dockPanelStruct.DockTopPortion;
            dockPanel.DockBottomPortion = dockPanelStruct.DockBottomPortion;

            // Set DockWindow ZOrders
            int prevMaxDockWindowZOrder = int.MaxValue;

            for (int i = 0; i < dockWindows.Length; i++)
            {
                int maxDockWindowZOrder = -1;
                int index = -1;
                for (int j = 0; j < dockWindows.Length; j++)
                {
                    if (dockWindows[j].ZOrderIndex > maxDockWindowZOrder && dockWindows[j].ZOrderIndex < prevMaxDockWindowZOrder)
                    {
                        maxDockWindowZOrder = dockWindows[j].ZOrderIndex;
                        index = j;
                    }
                }

                dockPanel.DockWindows[dockWindows[index].DockState].BringToFront();
                prevMaxDockWindowZOrder = maxDockWindowZOrder;
            }

            // Create Contents
            for (int i = 0; i < contents.Length; i++)
            {
                IDockableWindow content = deserializeContent(contents[i].PersistString);
                if (content == null)
                {
                    content = new DummyContent();
                }
                content.DockHandler.DockPanel       = dockPanel;
                content.DockHandler.AutoHidePortion = contents[i].AutoHidePortion;
                content.DockHandler.IsHidden        = true;
                content.DockHandler.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++)
                {
                    IDockableWindow 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.DockHandler.FloatPane = pane;
                    }
                    else
                    {
                        content.DockHandler.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 IDockContent 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]].DockHandler.Pane;
                        int      ZOrderIndex1 = pane1 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane1)].ZOrderIndex;
                        DockPane pane2        = dockPanel.Contents[sortedContents[j]].DockHandler.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 IDockContent first to avoid screen flickers
            for (int i = 0; i < contents.Length; i++)
            {
                IDockableWindow content = dockPanel.Contents[sortedContents[i]];
                if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState != DockState.Document)
                {
                    content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden;
                }
            }

            // after all non-document IDockContent, show document IDockContent
            for (int i = 0; i < contents.Length; i++)
            {
                IDockableWindow content = dockPanel.Contents[sortedContents[i]];
                if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState == DockState.Document)
                {
                    content.DockHandler.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].DockHandler.Form.Close();
                }
            }
        }
Exemplo n.º 26
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     return(_enumConverter.ConvertFrom(context, culture, value));
 }
Exemplo n.º 27
0
        /// <summary>
        /// 将int类型转化为自定义类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static T ToEnum <T>(this int value)
        {
            EnumConverter converter = new EnumConverter(typeof(T));

            return((T)converter.ConvertFrom(value.ToString()));
        }