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); } } } }
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); }
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); }
public CacheBag(CacheBag cb) { Methods = new ConcurrentBag <MethodInfo>(cb.Methods); Properties = new ConcurrentBag <PropertyInfo>(cb.Properties); Events = new ConcurrentBag <EventInfo>(cb.Events); }