public object?Convert(object?value, Type?targetType, object?parameter, CultureInfo?culture)
            {
                if (!IsConvertFunctionAvailable)
                {
                    EventSource.Log.MissingConvertFunction("convertFunction", ErrorStrategy.ToString());

                    return(GetErrorValue(DefaultOutputTypeValue));
                }

                if (targetType != null)
                {
                    if (!targetType.IsAssignableFrom(OutputType))
                    {
                        EventSource.Log.NonAssignableTargetType(targetType.Name, OutputType.Name, ErrorStrategy.ToString());

                        return(GetErrorValue(DefaultOutputTypeValue));
                    }
                }
                else
                {
                    EventSource.Log.NonRequestedTargetType();
                }

                return(ConvertInternal(value, parameter, culture));
            }
Example #2
0
            public override ValidationResult?Validate(object?value, CultureInfo?cultureInfo)
            {
                if (ruleFunction == null)
                {
                    EventSource.Log.MissingRuleFunction("ruleFunction", ErrorStrategy.ToString());

                    return(GetErrorValue());
                }

                return(ValidateInternal(value, cultureInfo));
            }
Example #3
0
            public override DataTemplate?SelectTemplate(object?item, DependencyObject?container)
            {
                if (selectFunction == null)
                {
                    EventSource.Log.MissingSelectTemplateFunction("selectFunction", ErrorStrategy.ToString());

                    return(GetErrorValue());
                }

                return(SelectTemplateInternal(item, container));
            }
            public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
            {
                if (!IsConvertBackFunctionAvailable)
                {
                    EventSource.Log.MissingConvertBackFunction("convertBackFunction", ErrorStrategy.ToString());

                    return(GetErrorValues(DefaultInputTypeValue, targetTypes));
                }

                if (targetTypes != null)
                {
                    for (var i = 0; i < targetTypes.Length; i++)
                    {
                        var targetType = targetTypes[i];
                        if (targetType != null)
                        {
                            if (!targetType.IsAssignableFrom(InputType))
                            {
                                EventSource.Log.NonAssignableTargetTypeAtPositionForBackConversion(
                                    targetType.Name,
                                    i,
                                    InputType.Name,
                                    ErrorStrategy.ToString());

                                return(GetErrorValues(DefaultInputTypeValue, targetTypes));
                            }
                        }
                        else
                        {
                            EventSource.Log.NonRequestedTargetTypeAtPosition(i);
                        }
                    }
                }
                else
                {
                    EventSource.Log.NonRequestedTargetType();
                }

                return(ConvertBackInternal(value, targetTypes, parameter, culture));
            }
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (!IsConvertBackFunctionAvailable)
                {
                    EventSource.Log.MissingConvertBackFunction("convertBackFunction", ErrorStrategy.ToString());

                    return(GetErrorValue(DefaultInputTypeValue));
                }

                if (targetType != null)
                {
                    if (!targetType.IsAssignableFrom(InputType))
                    {
                        EventSource.Log.NonAssignableTargetTypeForBackConversion(targetType.Name, InputType.Name, ErrorStrategy.ToString());

                        return(GetErrorValue(DefaultInputTypeValue));
                    }
                }
                else
                {
                    EventSource.Log.NonRequestedTargetType();
                }

                return(ConvertBackInternal(value, parameter, culture));
            }
Example #6
0
            ValidationResult?ValidateInternal(object?item, CultureInfo?cultureInfo)
            {
                I inputValue;

                try
                {
                    inputValue = (I)item !;
                }
                catch (SystemException e) when(e is InvalidCastException || e is NullReferenceException)
                {
                    EventSource.Log.UnableToCastToRuleInputType(item?.GetType().Name ?? "null", typeof(I).Name, ErrorStrategy.ToString());

                    return(GetErrorValue());
                }

                Debug.Assert(ruleFunction != null);

                return(ruleFunction !(new ValidationRuleArgs <I>(inputValue, cultureInfo)));
            }
Example #7
0
            DataTemplate?SelectTemplateInternal(object?item, DependencyObject?container)
            {
                I inputValue;

                try
                {
                    inputValue = (I)item !;
                }
                catch (SystemException e) when(e is InvalidCastException || e is NullReferenceException)
                {
                    EventSource.Log.UnableToCastToItemType(item?.GetType().Name ?? "null", typeof(I).Name, ErrorStrategy.ToString());

                    return(GetErrorValue());
                }

                Debug.Assert(selectFunction != null);

                return(selectFunction !(new TemplateSelectorArgs <I>(inputValue, container)));
            }