Exemple #1
0
        /// <summary>
        /// Searches the type and child types for a field that matches the given column name.
        /// </summary>
        /// <param name="type">The type to search.</param>
        /// <param name="columnName">The column to search for.</param>
        /// <param name="mappingCollection">The mapping collection containing the configuration for this context.</param>
        /// <returns>The name of the field or null if there is no match.</returns>
        internal static string SearchForMatchingField(Type type, string columnName, MappingCollection mappingCollection)
        {
            var queue = new Queue <Tuple <Type, string> >();

            queue.Enqueue(Tuple.Create(type, String.Empty));

            var searched = new HashSet <Type>();

            while (queue.Any())
            {
                var tuple  = queue.Dequeue();
                var t      = tuple.Item1;
                var prefix = tuple.Item2;
                searched.Add(t);

                var prop = GetMemberByColumnName(t, columnName);
                if (prop != null)
                {
                    return(prefix + prop.Name);
                }

                if (mappingCollection.CanBindChild(t))
                {
                    foreach (var p in ClassPropInfo.GetMembersForType(t).Where(m => !TypeHelper.IsAtomicType(m.MemberType)))
                    {
                        if (!searched.Contains(p.MemberType))
                        {
                            queue.Enqueue(Tuple.Create(p.MemberType, prefix + p.Name + MemberSeparator));
                        }
                    }
                }
            }

            return(null);
        }