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

            return stepArgumentTypeConverter.CanConvert(value, typeToConvertTo, bindingCulture);
        }
Пример #2
0
 public BindingMethod(IBindingType type, string name, IEnumerable<IBindingParameter> parameters, IBindingType returnType)
 {
     Type = type;
     Name = name;
     Parameters = parameters;
     ReturnType = returnType;
 }
Пример #3
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;
        }
Пример #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;
            }
        }
Пример #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)));
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #8
0
        private object ConvertArg(object value, IBindingType typeToConvertTo)
        {
            Debug.Assert(value != null);
            Debug.Assert(typeToConvertTo != null);

            return(_stepArgumentTypeConverter.Convert(value, typeToConvertTo, FeatureContext.BindingCulture));
        }
Пример #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);
        }
Пример #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));
        }
Пример #12
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;
        }
Пример #13
0
        private bool CanConvertArg(object value, IBindingType typeToConvertTo, CultureInfo bindingCulture)
        {
            if (typeToConvertTo.IsAssignableTo(value.GetType()))
            {
                return(true);
            }

            return(stepArgumentTypeConverter.CanConvert(value, typeToConvertTo, bindingCulture));
        }
Пример #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);
        }
Пример #16
0
        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;
        }
Пример #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));
        }
Пример #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));
        }
Пример #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;
        }
Пример #21
0
        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;
        }
Пример #22
0
        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;
        }
Пример #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;
        }
Пример #26
0
        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);
        }
Пример #27
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;
        }
        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);
        }
Пример #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));
            }
Пример #31
0
        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);
        }
Пример #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;
        }
Пример #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);
        }
Пример #34
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;
        }
Пример #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);
        }
Пример #36
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;
        }
Пример #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;
        }
    }
Пример #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);
            }
        }
Пример #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);
        }
Пример #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)));
        }
Пример #41
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));
        }
Пример #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));
        }
Пример #44
0
        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));
        }
Пример #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));
        }
Пример #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);
        }
Пример #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);
        }
Пример #48
0
        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));
        }
Пример #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));
            }
Пример #50
0
 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);
     }
 }
Пример #52
0
 public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     throw new NotSupportedException();
 }
Пример #53
0
 protected abstract object Convert(Table table, IBindingType typeToConvertTo, CultureInfo cultureInfo);
Пример #54
0
 private IStepArgumentTypeConverter GetConverter(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     return converters.FirstOrDefault(x => x.CanConvert(value, typeToConvertTo, cultureInfo));
 }
Пример #55
0
        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;
        }
Пример #56
0
 public BindingParameter(IBindingType type, string parameterName)
 {
     Type = type;
     ParameterName = parameterName;
 }
Пример #57
0
 public bool CanConvert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     return GetConverter(value, typeToConvertTo, cultureInfo) != null;
 }
Пример #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);
            }
Пример #59
0
 public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     return Convert((Table)value, typeToConvertTo, cultureInfo);
 }
Пример #60
0
 public object Convert(object value, IBindingType typeToConvertTo, CultureInfo cultureInfo)
 {
     var converter = GetConverter(value, typeToConvertTo, cultureInfo);
     return converter.Convert(value, typeToConvertTo, cultureInfo);
 }