Esempio n. 1
0
        private int ExecuteMatch(ConverterMatchContext context)
        {
            var targetType = context.TargetType;
            var sourceType = context.SourceType;

            var reflectingTargetType = targetType.GetTypeInfo();
            var reflectingSourceType = sourceType.GetTypeInfo();

            if (targetType.IsNullable() && sourceType.IsNullable())
            {
                var distance = MatchConvert(reflectingSourceType.GetGenericArguments()[0], reflectingTargetType.GetGenericArguments()[0]);
                if (distance != -1)
                {
                    return(distance + 2);
                }
            }
            if (targetType.IsNullable())
            {
                var distance = MatchConvert(sourceType, reflectingTargetType.GetGenericArguments()[0]);
                if (distance != -1)
                {
                    return(distance + 1);
                }
            }
            if (sourceType.IsNullable())
            {
                var distance = MatchConvert(reflectingSourceType.GetGenericArguments()[0], targetType);
                if (distance != -1)
                {
                    return(distance + 1);
                }
            }
            return(MatchConvert(sourceType, targetType));
        }
        public override int Match(ConverterMatchContext context)
        {
            var sourceDistance = ReflectionHelper.GetDistance(context.SourceType, typeof(TSource));
            var targetDistance = ReflectionHelper.GetDistance(context.TargetType, typeof(TTarget));

            return(sourceDistance == -1 || targetDistance == -1 ? -1 : sourceDistance + targetDistance);
        }
Esempio n. 3
0
 public override int Match(ConverterMatchContext context)
 {
     if (Equals(context.GetProperty(typeof(PrimitiveValueConverter)), true))
     {
         return(-1);
     }
     return(ExecuteMatch(context));
 }
 internal ValueConverter Find(ConverterMatchContext context)
 {
     return((from converter in _converters
             let score = converter.Match(context)
                         where score >= 0
                         orderby score, converter.Intrinsic ? 1 : 0
             select converter).FirstOrDefault());
 }
Esempio n. 5
0
        private ValueConverter FindConverter(Type sourceType, Type targetType)
        {
            var matchContext = new ConverterMatchContext(sourceType, targetType);

            matchContext.SetProperty(typeof(PrimitiveValueConverter), true);
            var converter = Container.Converters.Find(matchContext);

            if (ReferenceEquals(converter, this))
            {
                return(null);
            }
            return(converter);
        }
Esempio n. 6
0
        public override int Match(ConverterMatchContext context)
        {
            var sourceDistance = ReflectionHelper.GetDistance(context.SourceType, typeof(IEnumerable <>));

            if (sourceDistance == -1)
            {
                return(-1);
            }
            var targetDistance = ReflectionHelper.GetDistance(context.TargetType, typeof(IEnumerable <>));

            if (targetDistance == -1)
            {
                return(-1);
            }
            return(sourceDistance + targetDistance);
        }
Esempio n. 7
0
        public override int Match(ConverterMatchContext context)
        {
            if (context.SourceType == typeof(string))
            {
                var targetType = context.TargetType;
                if (targetType.IsNullable() && GetConvertMethod(targetType.GetTypeInfo().GetGenericArguments()[0]) != null)
                {
                    return(1);
                }

                if (GetConvertMethod(context.TargetType) != null)
                {
                    return(0);
                }
            }
            return(-1);
        }
Esempio n. 8
0
 public override int Match(ConverterMatchContext context)
 {
     return(context.TargetType == typeof(string) ? ReflectionHelper.GetDistance(context.SourceType, typeof(object)) : -1);
 }
Esempio n. 9
0
 public abstract int Match(ConverterMatchContext context);