本文整理汇总了C#中System.ComponentModel.EnumConverter.ConvertFromString方法的典型用法代码示例。如果您正苦于以下问题:C# EnumConverter.ConvertFromString方法的具体用法?C# EnumConverter.ConvertFromString怎么用?C# EnumConverter.ConvertFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.EnumConverter
的用法示例。
在下文中一共展示了EnumConverter.ConvertFromString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertFrom
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
char[] separator = new char[] { '\n' };
string[] strArray = ((string) value).Split(separator);
Keyframe[] keys = new Keyframe[strArray.Length - 2];
for (int i = 0; i < keys.Length; i++)
{
char[] chArray2 = new char[] { ',' };
string[] keyvals = strArray[i + 2].Split(chArray2);
keys[i] = new Keyframe(ParseKeyVal(keyvals, Val.Time), ParseKeyVal(keyvals, Val.Value), ParseKeyVal(keyvals, Val.InTangent), ParseKeyVal(keyvals, Val.OutTangent));
}
AnimationCurve curve = new AnimationCurve(keys);
EnumConverter converter = new EnumConverter(typeof(WrapMode));
curve.postWrapMode = (WrapMode) converter.ConvertFromString(strArray[0]);
curve.preWrapMode = (WrapMode) converter.ConvertFromString(strArray[1]);
return curve;
}
示例2: Main
static void Main(string[] args)
{
Console.WriteLine("使用 EnumConverter ");
{
EnumConverter converter = new EnumConverter(typeof(ProgrammingLanguage));
// 将字符串转换为枚举.
string langStr = "CS, Cpp, XAML";
Console.WriteLine("将字符串 \"{0}\" 转换为枚举...", langStr);
ProgrammingLanguage lang = (ProgrammingLanguage)converter.ConvertFromString(langStr);
Console.WriteLine("完成!");
// 将枚举转换为字符串.
Console.WriteLine("将枚举结果转换为字符串...");
langStr = converter.ConvertToString(lang);
Console.WriteLine("完成! \"{0}\"", langStr);
}
Console.WriteLine("\n使用 EnumDescriptionConverter ");
{
EnumDescriptionConverter converter = new EnumDescriptionConverter(
typeof(ProgrammingLanguage));
// 将枚举转换为字符串.
string langStr = "Visual C#, Visual C++, XAML";
Console.WriteLine("将字符串 \"{0}\" 转换为枚举...", langStr);
ProgrammingLanguage lang = (ProgrammingLanguage)converter.ConvertFromString(langStr);
Console.WriteLine("完成!");
// 将枚举转换为字符串.
Console.WriteLine("将枚举结果转换为字符串...");
langStr = converter.ConvertToString(lang);
Console.WriteLine("完成! \"{0}\"", langStr);
}
Console.ReadLine();
}
示例3: Load
public static ThumbnailSettings Load(XmlDocument document)
{
Size size;
InterpolationMode interpolationMode;
Color backColor;
ThreadPriority threadPriority;
SizeConverter sizeConv = new SizeConverter();
XmlElement sizeElem = document.SelectSingleNode("settings/thumbnail/size") as XmlElement;
if (sizeElem != null) {
try {
size = (Size)sizeConv.ConvertFromString(sizeElem.GetAttribute("value"));
}
catch {
size = DefaultSize;
}
}
else {
size = DefaultSize;
}
EnumConverter ipConv = new EnumConverter(typeof(InterpolationMode));
XmlElement ipmodeElem = document.SelectSingleNode("settings/thumbnail/interpolationMode") as XmlElement;
if (ipmodeElem != null) {
try {
interpolationMode = (InterpolationMode)ipConv.ConvertFromString(ipmodeElem.GetAttribute("value"));
}
catch {
interpolationMode = DefaultInterpolationMode;
}
}
else {
interpolationMode = DefaultInterpolationMode;
}
ColorConverter colorConv = new ColorConverter();
XmlElement bcolorElem = document.SelectSingleNode("settings/thumbnail/backColor") as XmlElement;
if (bcolorElem != null) {
try {
backColor = (Color)colorConv.ConvertFromString(bcolorElem.GetAttribute("value"));
}
catch {
backColor = DefaultBackColor;
}
}
else {
backColor = DefaultBackColor;
}
EnumConverter priorityConv = new EnumConverter(typeof(ThreadPriority));
XmlElement priorityElem = document.SelectSingleNode("settings/thumbnail/threadPriority") as XmlElement;
if (priorityElem != null) {
try {
threadPriority = (ThreadPriority)priorityConv.ConvertFromString(priorityElem.GetAttribute("value"));
}
catch {
threadPriority = DefaultThumbnailThreadPriority;
}
}
else {
threadPriority = DefaultThumbnailThreadPriority;
}
return new ThumbnailSettings(size, interpolationMode, backColor, threadPriority);
}
示例4: 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);
}
}
示例5: Load
public static FullScreenViewerSettings Load(XmlDocument document)
{
Resizer resizer;
InterpolationMode interpolationMode;
Color backColor;
ResizerConverter rsConv = new ResizerConverter();
XmlElement resizerElem = document.SelectSingleNode("settings/fullScreenViewer/resizer") as XmlElement;
if (resizerElem != null) {
try {
resizer = (Resizer)rsConv.ConvertFrom(null, null, resizerElem.GetAttribute("value"));
}
catch {
resizer = DefaultResizer;
}
}
else {
resizer = DefaultResizer;
}
EnumConverter ipConv = new EnumConverter(typeof(InterpolationMode));
XmlElement ipmodeElem = document.SelectSingleNode("settings/fullScreenViewer/interpolationMode") as XmlElement;
if (ipmodeElem != null) {
try {
interpolationMode = (InterpolationMode)ipConv.ConvertFromString(ipmodeElem.GetAttribute("value"));
}
catch {
interpolationMode = DefaultInterpolationMode;
}
}
else {
interpolationMode = DefaultInterpolationMode;
}
ColorConverter colorConv = new ColorConverter();
XmlElement bcolorElem = document.SelectSingleNode("settings/fullScreenViewer/backColor") as XmlElement;
if (bcolorElem != null) {
try {
backColor = (Color)colorConv.ConvertFromString(bcolorElem.GetAttribute("value"));
}
catch {
backColor = DefaultBackColor;
}
}
else {
backColor = DefaultBackColor;
}
return new FullScreenViewerSettings(resizer, interpolationMode, backColor);
}
示例6: SetCameraParam2
public void SetCameraParam2(int CntNum)
{
//int rt = 0;
//int model = 0;
string URL = "";
HttpWebRequest req = null;
WebResponse res = null;
int maxheight = 0, maxwidth = 0;
//모델 받아오기
//model = AV2K.pModel(CntNum);
URL = "http://" + m_Avips[CntNum - 1] + "/get?" + "model";
req = (HttpWebRequest)WebRequest.Create(URL);
req.Credentials = new NetworkCredential("admin", m_PassWord);
res = req.GetResponse();
StreamReader red = new StreamReader(res.GetResponseStream());
URL = red.ReadLine();
URL = URL.Substring(6);
setResolution(int.Parse(URL), ref maxwidth, ref maxheight);
red.Close();
res.Close();
//촬영영역 설정(left, top, width, height)
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "sensorleft=" + m_AvParam[CntNum - 1].left.ToString();
req = (HttpWebRequest)WebRequest.Create(URL);
req.Credentials = new NetworkCredential("admin", m_PassWord);
res = req.GetResponse();
res.Close();
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "sensortop=" + m_AvParam[CntNum - 1].top.ToString();
req = (HttpWebRequest)WebRequest.Create(URL);
req.Credentials = new NetworkCredential("admin", m_PassWord);
res = req.GetResponse();
res.Close();
if (m_AvParam[CntNum - 1].width > maxwidth)
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "sensorwidth=" + maxwidth.ToString();
else
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "sensorwidth=" + m_AvParam[CntNum - 1].width.ToString();
req = (HttpWebRequest)WebRequest.Create(URL);
req.Credentials = new NetworkCredential("admin", m_PassWord);
res = req.GetResponse();
res.Close();
if (m_AvParam[CntNum - 1].height > maxheight)
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "sensorheight=" + maxheight.ToString();
else
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "sensorheight=" + m_AvParam[CntNum - 1].height.ToString();
req = (HttpWebRequest)WebRequest.Create(URL);
req.Credentials = new NetworkCredential("admin", m_PassWord);
res = req.GetResponse();
res.Close();
//Day/Night 설정
EnumConverter fdn = new EnumConverter(typeof(DN_modes));
Int32 dn = (Int32)fdn.ConvertFromString(m_AvParam[CntNum - 1].dn_mode.ToString());
string dnmode = "";
switch (dn)
{
case (0):
dnmode = "auto";
break;
case (1):
dnmode = "day";
break;
case (2):
dnmode = "night";
break;
}
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "daynight=" + dnmode;
req = (HttpWebRequest)WebRequest.Create(URL);
req.Credentials = new NetworkCredential("admin", m_PassWord);
res = req.GetResponse();
res.Close();
//Light 모드 설정
EnumConverter fln = new EnumConverter(typeof(Light_modes));
Int32 ln = (Int32)fln.ConvertFromString(m_AvParam[CntNum - 1].light.ToString());
URL = "http://" + m_Avips[CntNum - 1] + "/set?" + "freq=" + ln.ToString();
req = (HttpWebRequest)WebRequest.Create(URL);
req.Credentials = new NetworkCredential("admin", m_PassWord);
res = req.GetResponse();
res.Close();
//카메라 촬영 모드 설정
switch (m_AvParam[CntNum - 1].CameraMode)
{
case (4):
dnmode = "highspeed";
break;
case (0):
dnmode = "speed";
//.........这里部分代码省略.........
示例7: SetCameraParam
public void SetCameraParam(int CntNum)
{
int rt = 0;
int model = 0;
model = AV2K.pModel(CntNum);
int maxheight = 0, maxwidth = 0;
setResolution(model, ref maxwidth, ref maxheight);
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSENSOR_LEFT, ref m_AvParam[CntNum - 1].left);
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSENSOR_TOP, ref m_AvParam[CntNum - 1].top);
if (m_AvParam[CntNum - 1].width > maxwidth)
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSENSOR_WIDTH, ref maxwidth);
else
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSENSOR_WIDTH, ref m_AvParam[CntNum - 1].width);
if (m_AvParam[CntNum - 1].height > maxheight)
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSENSOR_HEIGHT, ref maxheight);
else
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSENSOR_HEIGHT, ref m_AvParam[CntNum - 1].height);
EnumConverter fdn = new EnumConverter(typeof(DN_modes));
Int32 dn = (Int32)fdn.ConvertFromString(m_AvParam[CntNum - 1].dn_mode.ToString());
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpDAY_NIGHT_MODE, ref dn);
EnumConverter fln = new EnumConverter(typeof(Light_modes));
Int32 ln = (Int32)fln.ConvertFromString(m_AvParam[CntNum - 1].light.ToString());
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpLIGHTING, ref ln);
rt = AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpCAMERA_MODE, ref m_AvParam[CntNum - 1].CameraMode);
if (m_AvParam[CntNum - 1].CameraMode == 4)
AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSHORT_EXPOSURES, ref m_AvParam[CntNum - 1].ShutterSpeed);
rt = 4;
AV2K.pSetAV2000Parameter(CntNum, CAMERA_PARAMETER.cpSHARPNESS, ref rt);
Thread.Sleep(150);
}