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


C# IValueConverter.GetType方法代码示例

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


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

示例1: RegisterConverter

        public static void RegisterConverter(IValueConverter converter, string name = null)
        {
            if (RegisteredConverters.ContainsValue(converter))
            {
                return;
            }

            if (name == null)
            {
                name = converter.GetType().Name.Replace("Converter", string.Empty);
            }

            int count = 1;
            var key = name;
            while (RegisteredConverters.ContainsKey(key))
            {
                key = string.Format("{0}_{1}", name, count);
                count++;
            }

            RegisteredConverters.Add(key, converter);
        }
开发者ID:sgmunn,项目名称:Mobile.Mvvm,代码行数:22,代码来源:BindingParser.cs

示例2: 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

示例3: ConverterDescriptor

        public ConverterDescriptor(IValueConverter converter)
        {
            var attribute = (ValueConversionAttribute)converter.GetType().GetCustomAttributes(typeof(ValueConversionAttribute), true).SingleOrDefault();
            if (attribute == null)
                throw new Exception("Converter must have a ValueConverterAttribute to be wrapped in a descriptor");

            TargetType = attribute.TargetType;
            SourceType = attribute.SourceType;
            Converter = converter;
        }
开发者ID:pmacn,项目名称:ValueConverters,代码行数:10,代码来源:LinkedConverter.cs


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