本文整理汇总了C#中System.ComponentModel.EnumConverter.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# EnumConverter.IsValid方法的具体用法?C# EnumConverter.IsValid怎么用?C# EnumConverter.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.EnumConverter
的用法示例。
在下文中一共展示了EnumConverter.IsValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeBoxSettings
private void DeserializeBoxSettings(AnnotationBox boxSettings, XmlElement boxSettingsNode)
{
string font = boxSettingsNode.GetAttribute("font");
string color = boxSettingsNode.GetAttribute("color");
string italics = boxSettingsNode.GetAttribute("italics");
string bold = boxSettingsNode.GetAttribute("bold");
string numberOfLines = boxSettingsNode.GetAttribute("number-of-lines");
string truncation = boxSettingsNode.GetAttribute("truncation");
string justification = boxSettingsNode.GetAttribute("justification");
string verticalAlignment = boxSettingsNode.GetAttribute("vertical-alignment");
string fitWidth = boxSettingsNode.GetAttribute("fit-width");
string alwaysVisible = boxSettingsNode.GetAttribute("always-visible");
if (!String.IsNullOrEmpty(font))
boxSettings.Font = font;
if (!String.IsNullOrEmpty(color))
boxSettings.Color = color;
if (!String.IsNullOrEmpty(italics))
boxSettings.Italics = (String.Compare("true", italics, true) == 0);
if (!String.IsNullOrEmpty(bold))
boxSettings.Bold = (String.Compare("true", bold, true) == 0);
if (!String.IsNullOrEmpty(numberOfLines))
{
byte result;
if (!byte.TryParse(numberOfLines, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out result))
result = 1;
boxSettings.NumberOfLines = result;
}
if (!String.IsNullOrEmpty(fitWidth))
boxSettings.FitWidth = (String.Compare("true", fitWidth) == 0);
if (!String.IsNullOrEmpty(alwaysVisible))
boxSettings.AlwaysVisible = (String.Compare("true", alwaysVisible, true) == 0);
if (!String.IsNullOrEmpty(truncation))
{
AnnotationBox.TruncationBehaviour fromString = boxSettings.Truncation;
EnumConverter converter = new EnumConverter(typeof(AnnotationBox.TruncationBehaviour));
if (converter.IsValid(truncation))
boxSettings.Truncation = (AnnotationBox.TruncationBehaviour)converter.ConvertFromString(truncation);
}
if (!String.IsNullOrEmpty(justification))
{
AnnotationBox.JustificationBehaviour fromString = boxSettings.Justification;
EnumConverter converter = new EnumConverter(typeof(AnnotationBox.JustificationBehaviour));
if (converter.IsValid(justification))
boxSettings.Justification = (AnnotationBox.JustificationBehaviour)converter.ConvertFromString(justification);
}
if (!String.IsNullOrEmpty(verticalAlignment))
{
AnnotationBox.VerticalAlignmentBehaviour fromString = boxSettings.VerticalAlignment;
EnumConverter converter = new EnumConverter(typeof(AnnotationBox.VerticalAlignmentBehaviour));
if (converter.IsValid(verticalAlignment))
boxSettings.VerticalAlignment = (AnnotationBox.VerticalAlignmentBehaviour)converter.ConvertFromString(verticalAlignment);
}
XmlElement configurationSettings = (XmlElement)boxSettingsNode.SelectSingleNode("configuration-settings");
if (configurationSettings != null)
{
string showLabel = configurationSettings.GetAttribute("show-label");
string showLabelIfEmpty = configurationSettings.GetAttribute("show-label-if-empty");
if (!String.IsNullOrEmpty(showLabel))
boxSettings.ConfigurationOptions.ShowLabel = (String.Compare("true", showLabel, true) == 0);
if (!String.IsNullOrEmpty(showLabelIfEmpty))
boxSettings.ConfigurationOptions.ShowLabelIfValueEmpty = (String.Compare("true", showLabelIfEmpty, true) == 0);
}
}
示例2: IsValid
public override bool IsValid(ITypeDescriptorContext context, object value)
{
if (value != null)
{
if (value.GetType() == this.m_Type)
{
return true;
}
if (value.GetType() != typeof(string))
{
return false;
}
char[] separator = new char[] { '\n' };
string[] strArray = ((string) value).Split(separator);
if (strArray.Length < 2)
{
return false;
}
EnumConverter converter = new EnumConverter(typeof(WrapMode));
if (!converter.IsValid(strArray[0]))
{
return false;
}
if (!converter.IsValid(strArray[1]))
{
return false;
}
for (int i = 2; i < strArray.Length; i++)
{
char[] chArray2 = new char[] { ',' };
string[] strArray2 = strArray[i].Split(chArray2);
if (strArray2.Length != 4)
{
return false;
}
foreach (string str in strArray2)
{
float num3;
if (!float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out num3))
{
return false;
}
}
}
}
return true;
}