private bool CanConvertArg(object value, IBindingType typeToConvertTo, CultureInfo bindingCulture)
        {
            if (typeToConvertTo.IsAssignableTo(value.GetType()))
                return true;

            return stepArgumentTypeConverter.CanConvert(value, typeToConvertTo, bindingCulture);
        }
Beispiel #2
0
 public BindingMethod(IBindingType type, string name, IEnumerable<IBindingParameter> parameters, IBindingType returnType)
 {
     Type = type;
     Name = name;
     Parameters = parameters;
     ReturnType = returnType;
 }
        protected override object Convert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var runtimeBindingType = (RuntimeBindingType)typeToConvertTo;
            var verticalTable = GetVerticalTable(table, runtimeBindingType);
            var values = GetValues(verticalTable);
            var objectInitializationData = GetObjectInitializationData(values.Keys, runtimeBindingType.Type);
            var bindingTypes = objectInitializationData.GetBindingTypes();

            var convertedValues = values
                .Where(x => bindingTypes.ContainsKey(x.Key))
                .ToDictionary(
                    x => x.Key,
                    x => stepArgumentTypeConverter.Convert(x.Value, bindingTypes[x.Key], cultureInfo));
            var constructorParameters = objectInitializationData.Constructor.GetParameters()
                .Select(x => convertedValues[SanitizePropertyName(x.Name)]).ToArray();
            var result = objectInitializationData.Constructor.Invoke(constructorParameters);

            foreach (var property in objectInitializationData.PropertiesToSet)
            {
                var value = convertedValues[SanitizePropertyName(property.Name)];
                property.SetValue(result, value, null);
            }

            return result;
        }
Beispiel #4
0
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (!(typeToConvertTo is RuntimeBindingType))
                return false;

            try
            {
                Convert(value, typeToConvertTo, cultureInfo);
                return true;
            }
            catch (InvalidCastException)
            {
                return false;
            }
            catch (OverflowException)
            {
                return false;
            }
            catch (FormatException)
            {
                return false;
            }
            catch (ArgumentException)
            {
                return false;
            }
        }
Beispiel #5
0
        protected override bool CanConvert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var runtimeBindingType = typeToConvertTo as RuntimeBindingType;

            if (runtimeBindingType == null)
            {
                return(false);
            }

            var verticalTable = GetVerticalTable(table, runtimeBindingType);

            if (verticalTable == null)
            {
                return(false);
            }

            var values = GetValues(verticalTable);
            var objectInitializationData = GetObjectInitializationData(values.Keys, runtimeBindingType.Type);

            if (objectInitializationData == null)
            {
                return(false);
            }

            var bindingTypes = objectInitializationData.GetBindingTypes();

            return(values
                   .Where(x => bindingTypes.ContainsKey(x.Key))
                   .All(x => stepArgumentTypeConverter.CanConvert(x.Value, bindingTypes[x.Key], cultureInfo)));
        }
Beispiel #6
0
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (!(typeToConvertTo is RuntimeBindingType))
            {
                return(false);
            }

            try
            {
                Convert(value, typeToConvertTo, cultureInfo);
                return(true);
            }
            catch (InvalidCastException)
            {
                return(false);
            }
            catch (OverflowException)
            {
                return(false);
            }
            catch (FormatException)
            {
                return(false);
            }
            catch (ArgumentException)
            {
                return(false);
            }
        }
Beispiel #7
0
        protected override object Convert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var runtimeBindingType       = (RuntimeBindingType)typeToConvertTo;
            var verticalTable            = GetVerticalTable(table, runtimeBindingType);
            var values                   = GetValues(verticalTable);
            var objectInitializationData = GetObjectInitializationData(values.Keys, runtimeBindingType.Type);
            var bindingTypes             = objectInitializationData.GetBindingTypes();

            var convertedValues = values
                                  .Where(x => bindingTypes.ContainsKey(x.Key))
                                  .ToDictionary(
                x => x.Key,
                x => stepArgumentTypeConverter.Convert(x.Value, bindingTypes[x.Key], cultureInfo));
            var constructorParameters = objectInitializationData.Constructor.GetParameters()
                                        .Select(x => convertedValues[SanitizePropertyName(x.Name)]).ToArray();
            var result = objectInitializationData.Constructor.Invoke(constructorParameters);

            foreach (var property in objectInitializationData.PropertiesToSet)
            {
                var value = convertedValues[SanitizePropertyName(property.Name)];
                property.SetValue(result, value, null);
            }

            return(result);
        }
Beispiel #8
0
        private object ConvertArg(object value, IBindingType typeToConvertTo)
        {
            Debug.Assert(value != null);
            Debug.Assert(typeToConvertTo != null);

            return(_stepArgumentTypeConverter.Convert(value, typeToConvertTo, FeatureContext.BindingCulture));
        }
Beispiel #9
0
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var table = value as Table;
            if (table == null)
                return false;

            return CanConvert(table, typeToConvertTo, cultureInfo);
        }
Beispiel #10
0
        public BindingParameter(IBindingType type, string parameterName)
        {
            if (type == null) throw new ArgumentNullException("type");
            if (parameterName == null) throw new ArgumentNullException("parameterName");

            Type = type;
            ParameterName = parameterName;
        }
        private static object ConvertSimple(IBindingType typeToConvertTo, object value, CultureInfo cultureInfo)
        {
            if (!(typeToConvertTo is RuntimeBindingType))
            {
                throw new SpecFlowException("The StepArgumentTypeConverter can be used with runtime types only.");
            }

            return(ConvertSimple(((RuntimeBindingType)typeToConvertTo).Type, value, cultureInfo));
        }
        protected override bool CanConvert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var itemRuntimeType = GetItemRuntimeType(typeToConvertTo);
            if (itemRuntimeType == null || IsVerticalTable(table, itemRuntimeType))
                return false;

            var rowFetcher = GetValidRowFetcherDelegate(table, itemRuntimeType, cultureInfo);
            return rowFetcher != null;
        }
Beispiel #13
0
        private bool CanConvertArg(object value, IBindingType typeToConvertTo, CultureInfo bindingCulture)
        {
            if (typeToConvertTo.IsAssignableTo(value.GetType()))
            {
                return(true);
            }

            return(stepArgumentTypeConverter.CanConvert(value, typeToConvertTo, bindingCulture));
        }
Beispiel #14
0
        public static bool TypeEquals(this IBindingType type1, Type type2)
        {
            if (type1 is RuntimeBindingType)
            {
                return(((RuntimeBindingType)type1).Type == type2);
            }

            return(TypeEquals(type1, new RuntimeBindingType(type2)));
        }
        public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, true);

            if (stepTransformation == null)
                throw new SpecFlowException("The StepTransformationConverter cannot convert the specified value.");

            return DoTransform(stepTransformation, value, cultureInfo);
        }
        protected virtual IStepArgumentTransformationBinding GetMatchingStepTransformation(object value, IBindingType typeToConvertTo, bool traceWarning)
        {
            var stepTransformations = bindingRegistry.GetStepTransformations().Where(t => CanConvert(t, value, typeToConvertTo)).ToArray();
            if (stepTransformations.Length > 1 && traceWarning)
            {
                testTracer.TraceWarning(string.Format("Multiple step transformation matches to the input ({0}, target type: {1}). We use the first.", value, typeToConvertTo));
            }

            return stepTransformations.Length > 0 ? stepTransformations[0] : null;
        }
        public static bool TypeEquals(this IBindingType type1, IBindingType type2)
        {
            if (ReferenceEquals(type1, type2))
                return true;

            if (type1 == null || type2 == null)
                return false;

            return type1.FullName == type2.FullName;
        }
Beispiel #18
0
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var table = value as Table;

            if (table == null)
            {
                return(false);
            }

            return(CanConvert(table, typeToConvertTo, cultureInfo));
        }
Beispiel #19
0
        public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, cultureInfo, true);

            if (stepTransformation == null)
            {
                throw new SpecFlowException("The StepTransformationConverter cannot convert the specified value.");
            }

            return(DoTransform(stepTransformation, value, cultureInfo));
        }
Beispiel #20
0
        public BindingMethod(IBindingType type, string name, IEnumerable<IBindingParameter> parameters, IBindingType returnType)
        {
            if (type == null) throw new ArgumentNullException("type");
            if (name == null) throw new ArgumentNullException("name");
            if (parameters == null) throw new ArgumentNullException("parameters");

            Type = type;
            Name = name;
            Parameters = parameters;
            ReturnType = returnType;
        }
        private bool CanConvertArg(object value, IBindingType typeToConvertTo)
        {
            Debug.Assert(value != null);
            Debug.Assert(typeToConvertTo != null);

            if (typeToConvertTo.IsAssignableTo(value.GetType()))
                return true;

            //TODO: proper param matching
            //return stepArgumentTypeConverter.CanConvert(value, typeToConvertTo, FeatureContext.Current.BindingCulture);
            return false;
        }
        private object ConvertArg(object value, IBindingType typeToConvertTo)
        {
            Debug.Assert(value != null);
            Debug.Assert(typeToConvertTo != null);

            if (typeToConvertTo.IsAssignableTo(value.GetType()))
            {
                return(value);
            }

            return(stepArgumentTypeConverter.Convert(value, typeToConvertTo, FeatureContext.BindingCulture));
        }
        private bool CanConvert(IStepArgumentTransformationBinding stepTransformationBinding, object value, IBindingType typeToConvertTo)
        {
            if (!stepTransformationBinding.Method.ReturnType.TypeEquals(typeToConvertTo))
                return false;

            if (stepTransformationBinding.Regex != null)
            {
                return value is string && stepTransformationBinding.Regex.IsMatch((string)value);
            }

            return stepTransformationBinding.Method.Parameters.Count() == 1;
        }
Beispiel #24
0
        protected override bool CanConvert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var itemRuntimeType = GetItemRuntimeType(typeToConvertTo);

            if (itemRuntimeType == null || IsVerticalTable(table, itemRuntimeType))
            {
                return(false);
            }

            var rowFetcher = GetValidRowFetcherDelegate(table, itemRuntimeType, cultureInfo);

            return(rowFetcher != null);
        }
        public static bool TypeEquals(this IBindingType type1, IBindingType type2)
        {
            if (ReferenceEquals(type1, type2))
                return true;

            if (type1 == null || type2 == null)
                return false;

            if (type1 is RuntimeBindingType && type2 is RuntimeBindingType)
                return ((RuntimeBindingType)type1).Type.Equals(((RuntimeBindingType)type2).Type);

            return type1.FullName == type2.FullName;
        }
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (value == null) throw new ArgumentNullException("value");

            if (typeToConvertTo == value.GetType())
                return true;

            var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, false);
            if (stepTransformation != null)
                return true;

            return CanConvertSimple(typeToConvertTo, value, cultureInfo);
        }
        protected override object Convert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var itemRuntimeType = GetItemRuntimeType(typeToConvertTo);
            var rowFetcher = GetValidRowFetcherDelegate(table, itemRuntimeType, cultureInfo);
            var result = Array.CreateInstance(itemRuntimeType.Type, table.RowCount);

            for (int i = 0; i < result.Length; i++)
            {
                var item = stepArgumentTypeConverter.Convert(rowFetcher(i), itemRuntimeType, cultureInfo);
                result.SetValue(item, i);
            }

            return result;
        }
        public static bool TypeEquals(this IBindingType type1, IBindingType type2)
        {
            if (ReferenceEquals(type1, type2))
            {
                return(true);
            }

            if (type1 == null || type2 == null)
            {
                return(false);
            }

            return(type1.FullName == type2.FullName);
        }
Beispiel #29
0
        public static bool IsAssignableFrom(this Type baseType, IBindingType type)
        {
            if (type is IPolymorphicBindingType polymorphicBindingType)
            {
                return(polymorphicBindingType.IsAssignableTo(new RuntimeBindingType(baseType)));
            }

            if (type.FullName == baseType.FullName)
            {
                return(true);
            }

            return(false);
        }
            public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
            {
                if (!(typeToConvertTo is RuntimeBindingType))
                {
                    Type systemType = Type.GetType(typeToConvertTo.FullName, false);
                    if (systemType == null)
                    {
                        return(false);
                    }
                    typeToConvertTo = new RuntimeBindingType(systemType);
                }

                return(StepArgumentTypeConverter.CanConvertSimple(typeToConvertTo, value, cultureInfo));
            }
        private bool CanConvertArg(object value, IBindingType typeToConvertTo)
        {
            Debug.Assert(value != null);
            Debug.Assert(typeToConvertTo != null);

            if (typeToConvertTo.IsAssignableTo(value.GetType()))
            {
                return(true);
            }

            //TODO: proper param matching
            //return stepArgumentTypeConverter.CanConvert(value, typeToConvertTo, FeatureContext.Current.BindingCulture);
            return(false);
        }
Beispiel #32
0
        public BindingParameter(IBindingType type, string parameterName)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (parameterName == null)
            {
                throw new ArgumentNullException("parameterName");
            }

            Type          = type;
            ParameterName = parameterName;
        }
Beispiel #33
0
        protected override object Convert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var itemRuntimeType = GetItemRuntimeType(typeToConvertTo);
            var rowFetcher      = GetValidRowFetcherDelegate(table, itemRuntimeType, cultureInfo);
            var result          = Array.CreateInstance(itemRuntimeType.Type, table.RowCount);

            for (int i = 0; i < result.Length; i++)
            {
                var item = stepArgumentTypeConverter.Convert(rowFetcher(i), itemRuntimeType, cultureInfo);
                result.SetValue(item, i);
            }

            return(result);
        }
        private Func<int, object> GetValidRowFetcherDelegate(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (table.RowCount == 0)
                return x => null;

            var pivotTable = new PivotTable(table);
            if (stepArgumentTypeConverter.CanConvert(pivotTable.GetInstanceTable(0), typeToConvertTo, cultureInfo))
                return x => pivotTable.GetInstanceTable(x);

            if (table.Header.Count == 1 &&
                stepArgumentTypeConverter.CanConvert(table.Rows[0][0], typeToConvertTo, cultureInfo))
                return x => table.Rows[x][0];

            return null;
        }
Beispiel #35
0
        public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var runtimeType = (RuntimeBindingType)typeToConvertTo;

            if (runtimeType.Type.IsEnum && value is string)
                return Enum.Parse(runtimeType.Type, ((string)value).Replace(" ", ""), true);

            if (runtimeType.Type == typeof(Guid?) && string.IsNullOrEmpty(value as string))
                return null;

            if (runtimeType.Type == typeof(Guid) || runtimeType.Type == typeof(Guid?))
                return new GuidValueRetriever().GetValue(value as string);

            return System.Convert.ChangeType(value, runtimeType.Type, cultureInfo);
        }
        private RuntimeBindingType GetItemRuntimeType(IBindingType typeToConvertTo)
        {
            var runtimeType = typeToConvertTo as RuntimeBindingType;
            if (runtimeType == null)
                return null;

            var type = runtimeType.Type;

            if (type.IsArray && type.GetArrayRank() == 1)
                return new RuntimeBindingType(type.GetElementType());

            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
                return new RuntimeBindingType(type.GetGenericArguments()[0]);

            return null;
        }
Beispiel #37
0
        public CucumberExpressionParameterType(string name, IBindingType targetType, IEnumerable <ICucumberExpressionParameterTypeTransformation> transformations)
        {
            Name            = name;
            TargetType      = targetType;
            Transformations = transformations.ToArray();

            var regexStrings = Transformations.Select(tr => tr.Regex).Distinct().ToArray();

            if (regexStrings.Length > 1 && regexStrings.Contains(MatchAllRegex))
            {
                regexStrings = new[] { MatchAllRegex }
            }
            ;
            RegexStrings = regexStrings;
        }
    }
Beispiel #38
0
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var runtimeType = typeToConvertTo as RuntimeBindingType;

            if (runtimeType == null)
            {
                return(false);
            }

            var targetType = runtimeType.Type;

            if (value == null)
            {
                return(!targetType.IsValueType);
            }

            if (!targetType.IsEnum || targetType != typeof(Guid) || targetType != typeof(Guid?))
            {
                var convertible = value as IConvertible;
                if (convertible == null)
                {
                    return(value.GetType() == targetType);
                }
            }

            try
            {
                Convert(value, typeToConvertTo, cultureInfo);
                return(true);
            }
            catch (InvalidCastException)
            {
                return(false);
            }
            catch (OverflowException)
            {
                return(false);
            }
            catch (FormatException)
            {
                return(false);
            }
            catch (ArgumentException)
            {
                return(false);
            }
        }
Beispiel #39
0
        public static bool TypeEquals(this IBindingType type1, IBindingType type2)
        {
            if (ReferenceEquals(type1, type2))
            {
                return(true);
            }

            if (type1 == null || type2 == null)
            {
                return(false);
            }

            if (type1 is RuntimeBindingType && type2 is RuntimeBindingType)
            {
                return(((RuntimeBindingType)type1).Type == ((RuntimeBindingType)type2).Type);
            }

            return(type1.FullName == type2.FullName);
        }
Beispiel #40
0
        public static bool IsAssignableTo(this IBindingType baseType, Type type)
        {
            if (baseType is RuntimeBindingType)
            {
                return(type.IsAssignableFrom(((RuntimeBindingType)baseType).Type));
            }

            if (type.FullName == baseType.FullName)
            {
                return(true);
            }

            if (type.BaseType != null && IsAssignableTo(baseType, type.BaseType))
            {
                return(true);
            }

            return(type.GetInterfaces().Any(_if => IsAssignableTo(baseType, _if)));
        }
        protected override bool CanConvert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var runtimeBindingType = typeToConvertTo as RuntimeBindingType;
            if (runtimeBindingType == null)
                return false;

            var verticalTable = GetVerticalTable(table, runtimeBindingType);
            if (verticalTable == null)
                return false;

            var values = GetValues(verticalTable);
            var objectInitializationData = GetObjectInitializationData(values.Keys, runtimeBindingType.Type);
            if (objectInitializationData == null)
                return false;

            var bindingTypes = objectInitializationData.GetBindingTypes();
            return values
                .Where(x => bindingTypes.ContainsKey(x.Key))
                .All(x => stepArgumentTypeConverter.CanConvert(x.Value, bindingTypes[x.Key], cultureInfo));
        }
Beispiel #42
0
        public BindingMethod(IBindingType type, string name, IEnumerable <IBindingParameter> parameters, IBindingType returnType)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            Type       = type;
            Name       = name;
            Parameters = parameters;
            ReturnType = returnType;
        }
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (typeToConvertTo == value.GetType())
            {
                return(true);
            }

            var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, false);

            if (stepTransformation != null)
            {
                return(true);
            }

            return(CanConvertSimple(typeToConvertTo, value, cultureInfo));
        }
        public async Task <object> ConvertAsync(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, true);

            if (stepTransformation != null)
            {
                return(await DoTransformAsync(stepTransformation, value, cultureInfo));
            }

            if (typeToConvertTo is RuntimeBindingType convertToType && convertToType.Type.IsAssignableFrom(value.GetType()))
            {
                return(value);
            }

            return(ConvertSimple(typeToConvertTo, value, cultureInfo));
        }
Beispiel #45
0
        public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            var runtimeType = (RuntimeBindingType)typeToConvertTo;

            if (runtimeType.Type.IsEnum && value is string)
            {
                return(Enum.Parse(runtimeType.Type, ((string)value).Replace(" ", ""), true));
            }

            if (runtimeType.Type == typeof(Guid?) && string.IsNullOrEmpty(value as string))
            {
                return(null);
            }

            if (runtimeType.Type == typeof(Guid) || runtimeType.Type == typeof(Guid?))
            {
                return(new GuidValueRetriever().GetValue(value as string));
            }

            return(System.Convert.ChangeType(value, runtimeType.Type, cultureInfo));
        }
Beispiel #46
0
        private Func <int, object> GetValidRowFetcherDelegate(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (table.RowCount == 0)
            {
                return(x => null);
            }

            var pivotTable = new PivotTable(table);

            if (stepArgumentTypeConverter.CanConvert(pivotTable.GetInstanceTable(0), typeToConvertTo, cultureInfo))
            {
                return(x => pivotTable.GetInstanceTable(x));
            }

            if (table.Header.Count == 1 &&
                stepArgumentTypeConverter.CanConvert(table.Rows[0][0], typeToConvertTo, cultureInfo))
            {
                return(x => table.Rows[x][0]);
            }

            return(null);
        }
Beispiel #47
0
        private RuntimeBindingType GetItemRuntimeType(IBindingType typeToConvertTo)
        {
            var runtimeType = typeToConvertTo as RuntimeBindingType;

            if (runtimeType == null)
            {
                return(null);
            }

            var type = runtimeType.Type;

            if (type.IsArray && type.GetArrayRank() == 1)
            {
                return(new RuntimeBindingType(type.GetElementType()));
            }

            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable <>))
            {
                return(new RuntimeBindingType(type.GetGenericArguments()[0]));
            }

            return(null);
        }
        public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, false);

            if (stepTransformation != null)
            {
                return(true);
            }

            var convertToType = typeToConvertTo as RuntimeBindingType;

            if (convertToType != null && convertToType.Type.IsAssignableFrom(value.GetType()))
            {
                return(true);
            }

            return(CanConvertSimple(typeToConvertTo, value, cultureInfo));
        }
Beispiel #49
0
            public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
            {
                if (!(typeToConvertTo is RuntimeBindingType))
                {
                    try
                    {
                        // in some special cases, Type.GetType throws exception
                        // one of such case, if a Dictionary<string,string> step parameter is specified, see issue #340
                        Type systemType = Type.GetType(typeToConvertTo.FullName, false);
                        if (systemType == null)
                        {
                            return(false);
                        }
                        typeToConvertTo = new RuntimeBindingType(systemType);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                        return(false);
                    }
                }

                return(StepArgumentTypeConverter.CanConvertSimple(typeToConvertTo, value, cultureInfo));
            }
 public static bool CanConvertSimple(IBindingType typeToConvertTo, object value, CultureInfo cultureInfo)
 {
     try
     {
         ConvertSimple(typeToConvertTo, value, cultureInfo);
         return true;
     }
     catch (InvalidCastException)
     {
         return false;
     }
     catch (OverflowException)
     {
         return false;
     }
     catch (FormatException)
     {
         return false;
     }
     catch (ArgumentException)
     {
         return false;
     }
 }
 public static bool CanConvertSimple(IBindingType typeToConvertTo, object value, CultureInfo cultureInfo)
 {
     try
     {
         ConvertSimple(typeToConvertTo, value, cultureInfo);
         return(true);
     }
     catch (InvalidCastException)
     {
         return(false);
     }
     catch (OverflowException)
     {
         return(false);
     }
     catch (FormatException)
     {
         return(false);
     }
     catch (ArgumentException)
     {
         return(false);
     }
 }
Beispiel #52
0
 public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     throw new NotSupportedException();
 }
Beispiel #53
0
 protected abstract object Convert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo);
 private IStepArgumentTypeConverter GetConverter(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     return converters.FirstOrDefault(x => x.CanConvert(value, typeToConvertTo, cultureInfo));
 }
        private bool CanConvert(IStepArgumentTransformationBinding stepTransformationBinding, object value, IBindingType typeToConvertTo)
        {
            if (!stepTransformationBinding.Method.ReturnType.TypeEquals(typeToConvertTo))
                return false;

            if (stepTransformationBinding.Regex != null && value is string)
                return stepTransformationBinding.Regex.IsMatch((string) value);
            return true;
        }
 public BindingParameter(IBindingType type, string parameterName)
 {
     Type = type;
     ParameterName = parameterName;
 }
 public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     return GetConverter(value, typeToConvertTo, cultureInfo) != null;
 }
Beispiel #58
0
            public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
            {
                if (!(typeToConvertTo is RuntimeBindingType))
                {
                    Type systemType = Type.GetType(typeToConvertTo.FullName, false);
                    if (systemType == null)
                        return false;
                    typeToConvertTo = new RuntimeBindingType(systemType);
                }

                return StepArgumentTypeConverter.CanConvertSimple(typeToConvertTo, value, cultureInfo);
            }
Beispiel #59
0
 public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     return Convert((Table)value, typeToConvertTo, cultureInfo);
 }
 public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     var converter = GetConverter(value, typeToConvertTo, cultureInfo);
     return converter.Convert(value, typeToConvertTo, cultureInfo);
 }