Example #1
0
 private void LoadInterface(Type _interface, TypeInfoWrapper parent)
 {
     if (CheckNamespace(_interface.Namespace))
     {
         LoadType(_interface);
     }
     foreach (MethodInfo mi in _interface.GetRuntimeMethods())
     {
         if (CheckNamespace(mi.DeclaringType.Namespace) && (mi.IsPublic || mi.IsFamily) && !mi.IsSpecialName && !allTypes[parent].Methods.Contains(mi))
         {
             if (!allTypes[parent].Methods.Contains(mi))
             {
                 allTypes[parent].Methods.Add(mi);
             }
         }
     }
     foreach (PropertyInfo pi in _interface.GetRuntimeProperties())
     {
         if (!allTypes[parent].Properties.Contains(pi) && !allTypes[parent].Properties.Any(x => x.Name == pi.Name))
         {
             allTypes[parent].Properties.Add(pi);
         }
     }
     foreach (EventInfo ei in _interface.GetRuntimeEvents())
     {
         if (!allTypes[parent].Events.Contains(ei))
         {
             allTypes[parent].Events.Add(ei);
         }
     }
     foreach (Type type in _interface.GetInterfaces())
     {
         LoadInterface(type, parent);
     }
 }
Example #2
0
 private void LoadType(Type type)
 {
     if (type.IsGenericParameter)
     {
         type = type.GetGenericTypeDefinition();
     }
     if (!CheckNamespace(type.Namespace))
     {
         return;
     }
     if (allTypes.Keys.FirstOrDefault(x => x.TypeInfo == type.GetTypeInfo()) == null)
     {
         TypeInfoWrapper tiw = new TypeInfoWrapper(type);
         CacheBag        cb  = new CacheBag();
         allTypes[tiw] = cb;
         foreach (MethodInfo mi in type.GetRuntimeMethods())
         {
             if (CheckNamespace(mi.DeclaringType.Namespace) && (mi.IsPublic || mi.IsFamily) && !mi.IsSpecialName && !cb.Methods.Contains(mi))
             {
                 cb.Methods.Add(mi);
             }
             if (mi.IsDefined(typeof(ExtensionAttribute), false) && mi.IsStatic && mi.IsPublic)
             {
                 if (extensions.Keys.FirstOrDefault(x => x.TypeInfo == type.GetTypeInfo()) == null)
                 {
                     extensions[tiw] = new ConcurrentBag <MethodInfo>(new MethodInfo[] { mi });
                 }
                 else
                 {
                     extensions[tiw].Add(mi);
                 }
             }
         }
         var rt = type.GetRuntimeProperties();
         foreach (PropertyInfo pi in type.GetRuntimeProperties())
         {
             if ((pi.GetMethod.IsFamily || pi.GetMethod.IsPublic) && !cb.Properties.Any(x => x.Name == pi.Name))
             {
                 cb.Properties.Add(pi);
             }
         }
         foreach (EventInfo ei in type.GetRuntimeEvents())
         {
             cb.Events.Add(ei);
         }
         if (type.GetTypeInfo().IsInterface)
         {
             foreach (Type t in type.GetInterfaces())
             {
                 LoadInterface(t, tiw);
             }
         }
     }
 }
Example #3
0
        public CacheBag GetCacheBag(TypeInfoWrapper type)
        {
            if (!allTypes.ContainsKey(type))
            {
                return(null);
            }
            CacheBag cb = new CacheBag(allTypes[type]);

            foreach (ConcurrentBag <MethodInfo> bag in extensions.Values)
            {
                foreach (MethodInfo mi in bag)
                {
                    if (CheckTypeAndInterfaces(type, mi.GetParameters().FirstOrDefault()?.ParameterType.GetTypeInfo()))
                    {
                        cb.Methods.Add(mi);
                    }
                }
            }
            return(cb);
        }
 public MethodInfoWrapper(TypeInfoWrapper parent, MethodInfo method)
 {
     Parent = parent;
     Method = method;
 }
 public EventInfoWrapper(TypeInfoWrapper parent, EventInfo e)
 {
     Parent = parent;
     Event  = e;
 }
Example #6
0
        private async Task <EmbedBuilder> ShowTypesAsync(EmbedBuilder eb, EmbedAuthorBuilder eab, IEnumerable <TypeInfoWrapper> list)
        {
            TypeInfoWrapper first = list.First();
            DocsHttpResult  result;
            string          pageUrl = SanitizeDocsUrl($"{first.TypeInfo.Namespace}.{first.TypeInfo.Name}");

            try
            {
                result = await GetWebDocsAsync($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html", first);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                result = new DocsHttpResult($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html");
            }
            eab.Name = $"{(first.TypeInfo.IsInterface ? "Interface" : (first.TypeInfo.IsEnum ? "Enum" : "Type"))}: {first.TypeInfo.Namespace}.{first.DisplayName}";
            eab.Url  = result.Url;//$"{DocsUrlHandler.DocsBaseUrl}api/{first.Namespace}.{first.Name}.html";
            eb.AddField((x) =>
            {
                x.IsInline = true;
                x.Name     = "Docs:";
                x.Value    = FormatDocsUrl(eab.Url);
            });
            var githubUrl = await GithubRest.GetTypeUrlAsync(first);

            if (githubUrl != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = "Source:";
                    x.Value    = FormatGithubUrl(githubUrl);
                });
            }
            if (result.Summary != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Summary:";
                    x.Value    = result.Summary;
                });
            }
            if (result.Example != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Example:";
                    x.Value    = result.Example;
                });
            }
            CacheBag cb = _cache.GetCacheBag(first);

            if (cb.Methods.Count != 0)
            {
                int i       = 1;
                var methods = cb.Methods.RandomShuffle().Take(3);
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = $"Some methods ({methods.Count()}/{cb.Methods.Count}):";
                    x.Value    = String.Join("\n", methods.Select(y => $"``{i++}-``{(IsInherited(new MethodInfoWrapper(first, y)) ? " (i)" : "")} {y.Name}(...)"));
                });
            }
            if (cb.Properties.Count != 0)
            {
                int i          = 1;
                var properties = cb.Properties.RandomShuffle().Take(3);
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = $"Some properties ({properties.Count()}/{cb.Properties.Count}):";
                    x.Value    = String.Join("\n", properties.Select(y => $"``{i++}-``{(IsInherited(new PropertyInfoWrapper(first, y)) ? " (i)" : "")} {y.Name}"));
                });
            }
            if (first.TypeInfo.IsEnum)
            {
                var enumValues = first.TypeInfo.GetEnumNames();
                int i          = 1;
                var fields     = enumValues.RandomShuffle().Take(3);
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = $"Some fields ({fields.Count()}/{enumValues.Length}):";
                    x.Value    = String.Join("\n", fields.Select(y => $"``{i++}-`` {y}"));
                });
            }
            return(eb);
        }
Example #7
0
 public PropertyInfoWrapper(TypeInfoWrapper parent, PropertyInfo property)
 {
     Parent   = parent;
     Property = property;
 }
Example #8
0
 private bool CheckTypeAndInterfaces(TypeInfoWrapper toBeChecked, TypeInfo toSearch) => CheckTypeAndInterfaces(toBeChecked.TypeInfo, toSearch);