当前位置: 首页>>代码示例>>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;未经允许,请勿转载。