Example #1
0
        private WrapperPropInfo GetWrapperPropInfoFor(Dictionary <string, WrapperPropInfo> dict, string propName)
        {
            WrapperPropInfo wpi;

            if (!dict.TryGetValue(propName, out wpi))
            {
                wpi            = new WrapperPropInfo(this, propName, Repository);
                dict[propName] = wpi;
            }

            return(wpi);
        }
Example #2
0
        public Type GetListTypeFor(WrapperPropInfo wpi)
        {
            if (wpi.PropertyType.IsArray)
            {
                return(wpi.PropertyType.DeclaringType);
            }
            string fullPropName = wpi.FullNameDest;

            Type listType;

            string listTypeName;

            listType = LoadListTypeForProperty(fullPropName);

            if (listType != null)
            {
                return(listType);
            }

            // Try to find type from get*BySomething))
            if (fullPropName.EndsWith("s"))
            {
                string singularName = wpi.Name.Substring(0, wpi.Name.Length - 1);

                string singularGetNameStart = "get" + singularName + "By";

                Type guessedReturnType = wpi.ClassInfo.WrappedType
                                         .GetMethods(BindingFlags.Instance | BindingFlags.Public)
                                         .Where(mi => mi.ReturnType != typeof(void))
                                         .Where(mi => mi.Name.StartsWith(singularGetNameStart))
                                         .Where(mi => mi.Name.Length > singularGetNameStart.Length)
                                         .Select(mi => mi.ReturnType)
                                         .FirstOrDefault();

                if (guessedReturnType == null)
                {
                    // Try to find type from name
                    guessedReturnType = TargetAssembly.GetTypes()
                                        .Where(t => t.Name == "Html" + singularName || t.Name == singularName).FirstOrDefault();
                }

                if (guessedReturnType != null)
                {
                    Console.WriteLine("Guessed list type " + guessedReturnType.FullName + " for " + fullPropName);
                    return(guessedReturnType);
                }
            }

            listType = GetListTypeFor(fullPropName);

            return(listType);
        }
Example #3
0
        private WrapperPropInfo GetWrapperPropInfoFor(Dictionary<string, WrapperPropInfo> dict, string propName)
        {
            WrapperPropInfo wpi;

            if (!dict.TryGetValue(propName, out wpi))
            {
                wpi = new WrapperPropInfo(this, propName, Repository);
                dict[propName] = wpi;
            }

            return wpi;
        }
Example #4
0
        public Type GetListTypeFor(WrapperPropInfo wpi)
        {
            if (wpi.PropertyType.IsArray)
                return wpi.PropertyType.DeclaringType;
            string fullPropName = wpi.FullNameDest;

            Type listType;

            string listTypeName;

            listType = LoadListTypeForProperty(fullPropName);

            if (listType != null)
                return listType;

            // Try to find type from get*BySomething))
            if (fullPropName.EndsWith("s"))
            {
                string singularName = wpi.Name.Substring(0, wpi.Name.Length - 1);

                string singularGetNameStart = "get" + singularName + "By";

                Type guessedReturnType = wpi.ClassInfo.WrappedType
                    .GetMethods(BindingFlags.Instance | BindingFlags.Public)
                    .Where(mi => mi.ReturnType != typeof(void))
                    .Where(mi => mi.Name.StartsWith(singularGetNameStart))
                    .Where(mi => mi.Name.Length > singularGetNameStart.Length)
                    .Select(mi => mi.ReturnType)
                    .FirstOrDefault();

                if (guessedReturnType == null)
                {
                    // Try to find type from name
                    guessedReturnType = TargetAssembly.GetTypes()
                        .Where(t => t.Name == "Html" + singularName || t.Name == singularName).FirstOrDefault();
                }

                if (guessedReturnType != null)
                {
                    Console.WriteLine("Guessed list type " + guessedReturnType.FullName + " for " + fullPropName);
                    return guessedReturnType;
                }
            }

            listType = GetListTypeFor(fullPropName);

            return listType;
        }