本文整理汇总了C#中System.ComponentModel.EnumConverter.ConvertFrom方法的典型用法代码示例。如果您正苦于以下问题:C# EnumConverter.ConvertFrom方法的具体用法?C# EnumConverter.ConvertFrom怎么用?C# EnumConverter.ConvertFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.EnumConverter
的用法示例。
在下文中一共展示了EnumConverter.ConvertFrom方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
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);
}
示例2: ConvertFrom_Null
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");
}
}
示例3: ConvertBack
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;
}
}
示例4: LoadFloatWindows
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;
}
示例5: LoadPanes
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;
}
示例6: LoadFromXml
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];
//.........这里部分代码省略.........
示例7: LoadDockWindows
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;
}
示例8: ConvertFrom_String
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) {
示例9: ConvertFrom_EnumArray
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");
}
示例10: LoadWindowState
/// <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;
}
示例11: WriteTypeConvertedInstance
// 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;
}
示例12: ConvertFrom_String_Flags
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");
}
}