当前位置: 首页>>代码示例>>C#>>正文


C# IValueConverter.Convert方法代码示例

本文整理汇总了C#中IValueConverter.Convert方法的典型用法代码示例。如果您正苦于以下问题:C# IValueConverter.Convert方法的具体用法?C# IValueConverter.Convert怎么用?C# IValueConverter.Convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IValueConverter的用法示例。


在下文中一共展示了IValueConverter.Convert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEnumName

        static string GetEnumName(FieldInfo field, Enum value, IValueConverter nameConverter, bool splitNames) {
            if(nameConverter != null)
                return nameConverter.Convert(value, typeof(string), null, CultureInfo.CurrentCulture) as string;
            string name = DataAnnotationsAttributeHelper.GetFieldDisplayName(field) ??
#if !SILVERLIGHT
 TypeDescriptor.GetConverter(value.GetType()).ConvertTo(value, typeof(string)) as string
#else
                value.ToString()
#endif
;
            if(splitNames)
                return SplitStringHelper.SplitPascalCaseString(name);
            return name;
        }
开发者ID:ruisebastiao,项目名称:DevExpress.Mvvm.Free,代码行数:14,代码来源:EnumSourceHelper.cs

示例2: ConvertWithNullParameter_ShouldThrowArgumentNullException

 public void ConvertWithNullParameter_ShouldThrowArgumentNullException(IValueConverter converter)
 {
     try
     {
         result = converter.Convert(null, null, null, "");
         Assert.Fail("An exception should have been thrown");
     }
     catch (ArgumentNullException exception)
     {
         StringAssert.Contains(exception.Message, "");
     }
     catch(Exception e)
     {
         Assert.Fail("Wrong exception  has been thrown");
     }
 }
开发者ID:mhebestadt,项目名称:CateringKingCalculator,代码行数:16,代码来源:ConverterTestBase.cs

示例3: ConvertHelper

        private object ConvertHelper(IValueConverter converter, object value, Type targetType, object parameter, CultureInfo culture)
        {
            // use the StringFormat (if appropriate) in preference to the default converter
            string stringFormat = EffectiveStringFormat;
            Invariant.Assert(converter != null || stringFormat != null);

            // PreSharp uses message numbers that the C# compiler doesn't know about.
            // Disable the C# complaints, per the PreSharp documentation.
            #pragma warning disable 1634, 1691

            // PreSharp complains about catching NullReference (and other) exceptions.
            // It doesn't recognize that IsCritical[Application]Exception() handles these correctly.
            #pragma warning disable 56500

            object convertedValue = null;
            try
            {
                if (stringFormat != null)
                {
                    convertedValue = String.Format(culture, stringFormat, value);
                }
                else
                {
                    convertedValue = converter.Convert(value, targetType, parameter, culture);
                }
            }

            // Catch all exceptions.  There is no app code on the stack,
            // so the exception isn't actionable by the app.
            // Yet we don't want to crash the app.
            catch (Exception ex)
            {
                // the DefaultValueConverter can end up calling BaseUriHelper.GetBaseUri()
                // which can raise SecurityException if the app does not have the right FileIO privileges
                if (CriticalExceptions.IsCriticalApplicationException(ex))
                    throw;

                if (TraceData.IsEnabled)
                {
                    string name = String.IsNullOrEmpty(stringFormat) ? converter.GetType().Name : "StringFormat";
                    TraceData.Trace(TraceLevel,
                            TraceData.BadConverterForTransfer(
                                name,
                                AvTrace.ToStringHelper(value),
                                AvTrace.TypeName(value)),
                            this, ex);
                }
                convertedValue = DependencyProperty.UnsetValue;
            }
            catch // non CLS compliant exception
            {
                if (TraceData.IsEnabled)
                {
                    TraceData.Trace(TraceLevel,
                            TraceData.BadConverterForTransfer(
                                converter.GetType().Name,
                                AvTrace.ToStringHelper(value),
                                AvTrace.TypeName(value)),
                            this);
                }
                convertedValue = DependencyProperty.UnsetValue;
            }

            #pragma warning restore 56500
            #pragma warning restore 1634, 1691

            return convertedValue;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:68,代码来源:BindingExpression.cs

示例4: Convert

		public object Convert(object value, Type targetType, IValueConverter valueConverter)
		{
			object result = value;
			
			if (valueConverter != null)
			{
				var parameter = GetConverterParameter();
				result = valueConverter.Convert(value, targetType, parameter, CultureInfo.CurrentUICulture);
			}
				
			if (targetType != null)
			{
				var typeCode = System.Convert.GetTypeCode(value);
				if (typeCode != TypeCode.Object && typeCode != TypeCode.Empty)
				{
					try					
					{
						result = System.Convert.ChangeType(result, targetType);
					}
					catch (InvalidCastException)
					{
					}
				}
			}

			return result;
		}
开发者ID:RobertKozak,项目名称:MonoMobile.Views,代码行数:27,代码来源:MemberData.cs


注:本文中的IValueConverter.Convert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。