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();
 }
 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;
 }
Exemple #3
0
        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();
        }
Exemple #4
0
        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();
        }
        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();
        }