本文整理汇总了C#中System.ComponentModel.EnumConverter.ConvertToString方法的典型用法代码示例。如果您正苦于以下问题:C# EnumConverter.ConvertToString方法的具体用法?C# EnumConverter.ConvertToString怎么用?C# EnumConverter.ConvertToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.EnumConverter
的用法示例。
在下文中一共展示了EnumConverter.ConvertToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnimationCurveToString
private static string AnimationCurveToString(object value)
{
if (value == null)
{
return string.Empty;
}
AnimationCurve curve = (AnimationCurve) value;
StringBuilder builder = new StringBuilder();
EnumConverter converter = new EnumConverter(typeof(WrapMode));
builder.AppendFormat("{0}\n{1}", converter.ConvertToString(curve.postWrapMode), converter.ConvertToString(curve.preWrapMode));
foreach (Keyframe keyframe in curve.keys)
{
object[] args = new object[] { InvStr(keyframe.inTangent), InvStr(keyframe.outTangent), InvStr(keyframe.time), InvStr(keyframe.value) };
builder.AppendFormat("\n{0}, {1}, {2}, {3}", args);
}
return builder.ToString();
}
示例2: Serialize
public override object Serialize(IDesignerSerializationManager manager, object value)
{
CodeExpression left = null;
using (CodeDomSerializerBase.TraceScope("EnumCodeDomSerializer::Serialize"))
{
Enum[] enumArray;
if (!(value is Enum))
{
return left;
}
bool flag = false;
TypeConverter converter = TypeDescriptor.GetConverter(value);
if ((converter != null) && converter.CanConvertTo(typeof(Enum[])))
{
enumArray = (Enum[]) converter.ConvertTo(value, typeof(Enum[]));
flag = enumArray.Length > 1;
}
else
{
enumArray = new Enum[] { (Enum) value };
flag = true;
}
CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(value.GetType());
TypeConverter converter2 = new EnumConverter(value.GetType());
foreach (Enum enum2 in enumArray)
{
string str = (converter2 != null) ? converter2.ConvertToString(enum2) : null;
CodeExpression right = !string.IsNullOrEmpty(str) ? new CodeFieldReferenceExpression(targetObject, str) : null;
if (right != null)
{
if (left == null)
{
left = right;
}
else
{
left = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.BitwiseOr, right);
}
}
}
if ((left != null) && flag)
{
left = new CodeCastExpression(value.GetType(), left);
}
}
return left;
}
示例3: 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();
}
示例4: Save
internal void Save(XmlWriter writer)
{
writer.WriteStartElement("thumbnail");
SizeConverter sizeConv = new SizeConverter();
writer.WriteStartElement("size");
writer.WriteAttributeString("value", sizeConv.ConvertToString(size));
writer.WriteEndElement();
EnumConverter ipConv = new EnumConverter(typeof(InterpolationMode));
writer.WriteStartElement("interpolationMode");
writer.WriteAttributeString("value", ipConv.ConvertToString(interpolationMode));
writer.WriteEndElement();
ColorConverter colorConv = new ColorConverter();
writer.WriteStartElement("backColor");
writer.WriteAttributeString("value", colorConv.ConvertToString(backColor));
writer.WriteEndElement();
EnumConverter priorityConv = new EnumConverter(typeof(ThreadPriority));
writer.WriteStartElement("threadPriority");
writer.WriteAttributeString("value", priorityConv.ConvertToString(threadPriority));
writer.WriteEndElement();
writer.WriteEndElement();
}
示例5: Save
internal void Save(XmlWriter writer)
{
writer.WriteStartElement("fullScreenViewer");
ResizerConverter rsConv = new ResizerConverter();
writer.WriteStartElement("resizer");
writer.WriteAttributeString("value", (string)rsConv.ConvertTo(null, null, resizer, typeof(string)));
writer.WriteEndElement();
EnumConverter ipConv = new EnumConverter(typeof(InterpolationMode));
writer.WriteStartElement("interpolationMode");
writer.WriteAttributeString("value", ipConv.ConvertToString(interpolationMode));
writer.WriteEndElement();
ColorConverter colorConv = new ColorConverter();
writer.WriteStartElement("backColor");
writer.WriteAttributeString("value", colorConv.ConvertToString(backColor));
writer.WriteEndElement();
writer.WriteEndElement();
}