Exemple #1
0
        public override bool UseWhen()
        {
            Info = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(TargetType, ColumnName);

            //could not find the property on the object
            return(Info != null);
        }
Exemple #2
0
        public override bool UseWhen()
        {
            // do deep property binding
            if (!(ColumnName.Contains('.')))
            {
                return(false);
            }

            var propertyNames = ColumnName.Split('.');

            if (propertyNames.Count() <= 1)
            {
                throw new Exception(string.Format("Can not find any property represented by deep-binding syntax: \"{0}\"", ColumnName));
            }

            Info = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(TargetType, propertyNames[0]);

            var nextColumnName = string.Join(".", propertyNames.Skip(1).ToList());

            deepAction = ColumnActionFactory.GetAction <ICreatorColumnAction>(Info.PropertyType, nextColumnName);

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

            return(deepAction.UseWhen());
        }
        public override bool UseWhen()
        {
            _info = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(TargetType, ColumnName);

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

            if (typeof(string).IsAssignableFrom(_info.PropertyType))
            {
                return(false);
            }

            if (typeof(IList).IsAssignableFrom(_info.PropertyType))
            {
                return(true);
            }

            if (IsGenericList(_info.PropertyType))
            {
                return(true);
            }

            if (typeof(IEnumerable).IsAssignableFrom(_info.PropertyType))
            {
                return(true);
            }

            return(false);
        }
Exemple #4
0
        private bool UseWhenProperty(string firstColumnName)
        {
            _info = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(
                TargetType, firstColumnName);

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

            _info = PropertyInfoHelper.GetIndexerPropertyInfo(
                TargetType, firstColumnName);

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

            _isIndexer = true;

            var parameterType = _info.GetIndexParameters().First().ParameterType;

            _lookUp = Convert.ChangeType(firstColumnName, parameterType);

            return(true);
        }
        public override bool UseWhen()
        {
            Info = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(TargetType, ColumnName);

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

            var assignable = (typeof(IList).IsAssignableFrom(Info.PropertyType));

            return(assignable);
        }
Exemple #6
0
        public object Do(PropertyInfo info, string tableValue)
        {
            // get the link from recallaid
            // then traverse the object getting each property until the last one
            // then return it's value

            var splits = tableValue.Split('.').ToList();
            var tag    = splits[0];

            if (!RecallAid.It.ContainsKey(tag))
            {
                throw new Exception("Could not find tag/link: " + tag);
            }

            var recalledValue = RecallAid.It[tag];

            if (recalledValue == null)
            {
                throw new Exception("Could not find tag/link: " + tableValue);
            }

            object propertyValue        = recalledValue;
            string previousPropertyName = tag;

            foreach (var propertyName in splits.Skip(1))
            {
                if (propertyValue == null)
                {
                    throw new Exception(string.Format("Property is null \"{0}\" in tag \"{1}\"", previousPropertyName, tableValue));
                }

                var targetProperty = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(propertyValue.GetType(), propertyName);

                if (targetProperty == null)
                {
                    throw new Exception(string.Format("Could not find property \"{0}\" in tag \"{1}\"", propertyName, tableValue));
                }

                propertyValue        = targetProperty.GetValue(propertyValue, null);
                previousPropertyName = propertyName;
            }

            return(propertyValue);
        }
Exemple #7
0
        /// <summary>
        ///   Used to create a Lambda Member Lookup based on Type and Specflow Table.
        ///   Resulting CustomComparer can be used in Collection Comparer and Fancy Printers
        /// </summary>
        private static CustomComparer <T> ComparerCreator <T>(Table table)
        {
            var contentComparer = CustomComparer <T> .CreateNew();

            for (var i = 0; i < table.Header.Count(); i++)
            {
                var propertyInfo = PropertyInfoHelper.GetCaseInsensitivePropertyInfo(typeof(T), table.Header.ElementAt(i));

                if (propertyInfo != null)
                {
                    // One dynamic property on the fly
                    var entityParam          = Expression.Parameter(typeof(T), "e");
                    var memberExpressionReal = Expression.MakeMemberAccess(entityParam, propertyInfo);
                    var memberExpressionObj  = Expression.Convert(memberExpressionReal, typeof(object));
                    var exp = Expression.Lambda <Func <T, object> >(memberExpressionObj, entityParam);

                    contentComparer.Add(exp);
                }
            }

            return(contentComparer);
        }