當前位置: 首頁>>代碼示例>>C#>>正文


C# ComponentModel.EnumConverter類代碼示例

本文整理匯總了C#中System.ComponentModel.EnumConverter的典型用法代碼示例。如果您正苦於以下問題:C# EnumConverter類的具體用法?C# EnumConverter怎麽用?C# EnumConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EnumConverter類屬於System.ComponentModel命名空間,在下文中一共展示了EnumConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CanConvertTo

		public void CanConvertTo ()
		{
			EnumConverter converter = new EnumConverter (typeof (E));
			Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#A1");
			Assert.IsFalse (converter.CanConvertTo (typeof (Enum)), "#A2");
			Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#A3");
			Assert.IsFalse (converter.CanConvertTo (typeof (int)), "#A4");
			Assert.IsTrue (converter.CanConvertTo (typeof (InstanceDescriptor)), "#A5");
			Assert.IsFalse (converter.CanConvertTo (typeof (string [])), "#A6");
#if NET_2_0
			Assert.IsTrue (converter.CanConvertTo (typeof (Enum [])), "#A7");
#else
			Assert.IsFalse (converter.CanConvertTo (typeof (Enum [])), "#A7");
#endif

			converter = new EnumConverter (typeof (E2));
			Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#B1");
			Assert.IsFalse (converter.CanConvertTo (typeof (Enum)), "#B2");
			Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#B3");
			Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#B4");
			Assert.IsTrue (converter.CanConvertTo (typeof (InstanceDescriptor)), "#B5");
			Assert.IsFalse (converter.CanConvertTo (typeof (string [])), "#B6");
#if NET_2_0
			Assert.IsTrue (converter.CanConvertTo (typeof (Enum [])), "#B7");
#else
			Assert.IsFalse (converter.CanConvertTo (typeof (Enum [])), "#B7");
#endif
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:28,代碼來源:EnumConverterTests.cs

示例2: GetSerializeAs

		internal static SettingsSerializeAs GetSerializeAs(string serializeAs)
		{
			var converter = new EnumConverter(typeof(SettingsSerializeAs));
			if (!String.IsNullOrEmpty(serializeAs))
				return (SettingsSerializeAs)converter.ConvertFromInvariantString(serializeAs);

			return default(SettingsSerializeAs);
		}
開發者ID:nhannd,項目名稱:Xian,代碼行數:8,代碼來源:SystemConfigurationHelper.cs

示例3: GetTypeConverter

		private static TypeConverter GetTypeConverter(Type from, Type converter)
		{
			TypeConverter typeConverter;
			if (converter == typeof(EnumConverter))
				typeConverter = new EnumConverter(from);
			else
				typeConverter = (TypeConverter)Activator.CreateInstance(converter);
			return typeConverter;
		}
開發者ID:ericziko,項目名稱:navigation,代碼行數:9,代碼來源:ConverterFactory.cs

示例4: SettingsMapping

		public SettingsMapping (XPathNavigator nav)
		{
			_sectionTypeName = nav.GetAttribute ("sectionType", String.Empty);
			_mapperTypeName = nav.GetAttribute ("mapperType", String.Empty);

			EnumConverter cvt = new EnumConverter (typeof (SettingsMappingPlatform));
			_platform = (SettingsMappingPlatform) cvt.ConvertFromInvariantString (nav.GetAttribute ("platform", String.Empty));

			LoadContents (nav);
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:10,代碼來源:SettingsMapping.cs

示例5: 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);
        }
開發者ID:SuperJMN,項目名稱:Glass,代碼行數:12,代碼來源:FlaggedEnumConverter.cs

示例6: JsonFxAOT

        private JsonFxAOT()
        {
            System.ComponentModel.TypeConverter c;

            c = new ArrayConverter();
            m_fakeFlag = c.Equals(c);
            //c = new BaseNumberConverter();
            //m_fakeFlag = c.Equals(c);
            c = new BooleanConverter();
            m_fakeFlag = c.Equals(c);
            c = new ByteConverter();
            m_fakeFlag = c.Equals(c);
            c = new CollectionConverter();
            m_fakeFlag = c.Equals(c);
            c = new ComponentConverter(typeof(int));
            m_fakeFlag = c.Equals(c);
            c = new CultureInfoConverter();
            m_fakeFlag = c.Equals(c);
            c = new DateTimeConverter();
            m_fakeFlag = c.Equals(c);
            c = new DecimalConverter();
            m_fakeFlag = c.Equals(c);
            c = new DoubleConverter();
            m_fakeFlag = c.Equals(c);
            c = new EnumConverter(typeof(int));
            m_fakeFlag = c.Equals(c);
            c = new ExpandableObjectConverter();
            m_fakeFlag = c.Equals(c);
            c = new Int16Converter();
            m_fakeFlag = c.Equals(c);
            c = new Int32Converter();
            m_fakeFlag = c.Equals(c);
            c = new Int64Converter();
            m_fakeFlag = c.Equals(c);
            c = new NullableConverter(typeof(object));
            m_fakeFlag = c.Equals(c);
            c = new SByteConverter();
            m_fakeFlag = c.Equals(c);
            c = new SingleConverter();
            m_fakeFlag = c.Equals(c);
            c = new StringConverter();
            m_fakeFlag = c.Equals(c);
            c = new TimeSpanConverter();
            m_fakeFlag = c.Equals(c);
            c = new UInt16Converter();
            m_fakeFlag = c.Equals(c);
            c = new UInt32Converter();
            m_fakeFlag = c.Equals(c);
            c = new UInt64Converter();
            m_fakeFlag = c.Equals(c);
        }
開發者ID:RosimInc,項目名稱:OJam2015,代碼行數:51,代碼來源:JsonFxAOT.cs

示例7: EnumeratedTypeChooser

        public EnumeratedTypeChooser(Type enumType)
        {
            if (enumType.IsEnumType() == false)
                throw new ArgumentException("The parameter enumType must be an Enum type. Nullable Enum types are also accepted. Other types are not allowed.");

            ec = new EnumConverter(enumType);

            InitializeComponent();

            foreach (var val in Enum.GetValues(enumType))
            {
                cmbValue.Items.Add(val);
            }
        }
開發者ID:rraguso,項目名稱:protone-suite,代碼行數:14,代碼來源:EnumeratedTypeChooser.cs

示例8: 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");
			}
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:15,代碼來源:EnumConverterTests.cs

示例9: 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;
 }
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:47,代碼來源:EnumCodeDomSerializer.cs

示例10: 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;
 }
開發者ID:CarlosHBC,項目名稱:UnityDecompiled,代碼行數:17,代碼來源:AnimationCurveTypeConverter.cs

示例11: 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();
 }
開發者ID:CarlosHBC,項目名稱:UnityDecompiled,代碼行數:17,代碼來源:AnimationCurveTypeConverter.cs

示例12: 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;
            }
        }
開發者ID:SuperJMN,項目名稱:Glass,代碼行數:19,代碼來源:FlaggedEnumConverter.cs

示例13: GetConverter

        /// <summary>
        /// Returns <see cref="TypeConverter"/> for the specified type.
        /// </summary>
        /// <param name="type">Type to get the converter for.</param>
        /// <returns>a type converter for the specified type.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="type"/> is <c>null</c>.</exception>
        public static TypeConverter GetConverter(Type type)
        {
            AssertUtils.ArgumentNotNull(type, "type");

            TypeConverter converter;
            if (!_converters.TryGetValue(type, out converter))
            {
                if (type.IsEnum)
                {
                    converter = new EnumConverter(type);
                }
                else
                {
                    converter = TypeDescriptor.GetConverter(type);
                }
            }

            return converter;
        }
開發者ID:kog,項目名稱:Solenoid-Expressions,代碼行數:25,代碼來源:TypeConverterRegistry.cs

示例14: 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();
        }
開發者ID:zealoussnow,項目名稱:OneCode,代碼行數:37,代碼來源:Program.cs

示例15: 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);
				}
			}
開發者ID:nhannd,項目名稱:Xian,代碼行數:71,代碼來源:AnnotationLayoutStore.cs


注:本文中的System.ComponentModel.EnumConverter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。