static ApiEntry ForField(ProgrammableBlockApi api, Whitelist whitelist, FieldInfo fieldInfo) { if (fieldInfo.IsSpecialName || !fieldInfo.IsPublic && !fieldInfo.IsFamily && !fieldInfo.IsFamilyOrAssembly && !fieldInfo.IsFamilyOrAssembly) { return(null); } var basis = api.GetEntry(fieldInfo.DeclaringType); var xmlDocKey = $"F{basis.XmlDocKey.Substring(1)}.{fieldInfo.Name}"; return(new ApiEntry(api, fieldInfo, basis.AssemblyName, basis.NamespaceName, fieldInfo.Name, xmlDocKey, whitelist.IsWhitelisted(fieldInfo))); }
static ApiEntry ForEvent(ProgrammableBlockApi api, Whitelist whitelist, EventInfo eventInfo) { if (eventInfo.IsSpecialName || !(eventInfo.AddMethod?.IsPublic ?? false) && !(eventInfo.AddMethod?.IsFamily ?? false) && !(eventInfo.AddMethod?.IsFamilyOrAssembly ?? false) && !(eventInfo.AddMethod?.IsFamilyOrAssembly ?? false) && !(eventInfo.RemoveMethod?.IsPublic ?? false) && !(eventInfo.RemoveMethod?.IsFamily ?? false) && !(eventInfo.RemoveMethod?.IsFamilyOrAssembly ?? false) && !(eventInfo.RemoveMethod?.IsFamilyOrAssembly ?? false)) { return(null); } var basis = api.GetEntry(eventInfo.DeclaringType); var xmlDocKey = $"E{basis.XmlDocKey.Substring(1)}.{eventInfo.Name}"; return(new ApiEntry(api, eventInfo, basis.AssemblyName, basis.NamespaceName, eventInfo.Name, xmlDocKey, whitelist.IsWhitelisted(eventInfo))); }
static string XmlDocParameterStr(ProgrammableBlockApi api, ParameterInfo parameterInfo) { var type = parameterInfo.ParameterType.IsByRef || parameterInfo.ParameterType.IsPointer ? parameterInfo.ParameterType.GetElementType() : parameterInfo.ParameterType; //if (type.IsGenericType && !type.IsGenericTypeDefinition) // type = type.GetGenericTypeDefinition(); if (parameterInfo.ParameterType.IsByRef) { if (type.FullName == null) { return(type.Name + "@"); } return(api.GetEntry(type).XmlDocKey.Substring(2) + "@"); } if (type.FullName == null) { return(type.Name); } return(api.GetEntry(type, true).XmlDocKey.Substring(2)); }
static ApiEntry ForProperty(ProgrammableBlockApi api, Whitelist whitelist, PropertyInfo propertyInfo) { if (propertyInfo.IsSpecialName || !(propertyInfo.GetMethod?.IsPublic ?? false) && !(propertyInfo.GetMethod?.IsFamily ?? false) && !(propertyInfo.GetMethod?.IsFamilyOrAssembly ?? false) && !(propertyInfo.GetMethod?.IsFamilyOrAssembly ?? false) && !(propertyInfo.SetMethod?.IsPublic ?? false) && !(propertyInfo.SetMethod?.IsFamily ?? false) && !(propertyInfo.SetMethod?.IsFamilyOrAssembly ?? false) && !(propertyInfo.SetMethod?.IsFamilyOrAssembly ?? false)) { return(null); } var basis = api.GetEntry(propertyInfo.DeclaringType); var xmlDocKey = $"P{basis.XmlDocKey.Substring(1)}.{propertyInfo.Name}"; return(new ApiEntry(api, propertyInfo, basis.AssemblyName, basis.NamespaceName, propertyInfo.Name, xmlDocKey, whitelist.IsWhitelisted(propertyInfo))); }
static ApiEntry ForConstructor(ProgrammableBlockApi api, Whitelist whitelist, ConstructorInfo constructorInfo) { //if (constructorInfo.IsSpecialName || !constructorInfo.IsPublic && !constructorInfo.IsFamily && !constructorInfo.IsFamilyOrAssembly && !constructorInfo.IsFamilyOrAssembly) // return null; if (!constructorInfo.IsPublic && !constructorInfo.IsFamily && !constructorInfo.IsFamilyOrAssembly && !constructorInfo.IsFamilyOrAssembly) { return(null); } var basis = api.GetEntry(constructorInfo.DeclaringType); var xmlDocKey = $"C{basis.XmlDocKey.Substring(1)}.{constructorInfo.Name}"; var parameters = constructorInfo.GetParameters(); xmlDocKey += "(" + string.Join(",", parameters.Select(p => XmlDocParameterStr(api, p))) + ")"; return(new ApiEntry(api, constructorInfo, basis.AssemblyName, basis.NamespaceName, constructorInfo.Name, xmlDocKey, whitelist.IsWhitelisted(constructorInfo))); }
static ApiEntry ForMethod(ProgrammableBlockApi api, Whitelist whitelist, MethodInfo methodInfo) { if (methodInfo.IsSpecialName || !methodInfo.IsPublic && !methodInfo.IsFamily && !methodInfo.IsFamilyOrAssembly && !methodInfo.IsFamilyOrAssembly) { return(null); } if (methodInfo.IsGenericMethodDefinition || methodInfo.IsGenericMethod) { return(ForGenericMethod(api, whitelist, methodInfo)); } var basis = api.GetEntry(methodInfo.DeclaringType); var xmlDocKey = $"M{basis.XmlDocKey.Substring(1)}.{methodInfo.Name}"; var parameters = methodInfo.GetParameters(); if (parameters.Length > 0) { xmlDocKey += $"({string.Join(",", parameters.Select(p => XmlDocParameterStr(api, p)))})"; } return(new ApiEntry(api, methodInfo, basis.AssemblyName, basis.NamespaceName, methodInfo.Name, xmlDocKey, whitelist.IsWhitelisted(methodInfo))); }
static ApiEntry ForGenericMethod(ProgrammableBlockApi api, Whitelist whitelist, MethodInfo methodInfo) { var basis = api.GetEntry(methodInfo.DeclaringType); var name = methodInfo.Name; var separatorIndex = name.IndexOf('`'); if (separatorIndex >= 0) { name = name.Substring(0, separatorIndex); } var xmlDocKey = $"M{basis.XmlDocKey.Substring(1)}.{methodInfo.Name}"; var genericArguments = methodInfo.GetGenericArguments(); xmlDocKey += $"{{{string.Join(",", genericArguments.Select(arg => arg.Name))}}}"; var parameters = methodInfo.GetParameters(); if (parameters.Length > 0) { xmlDocKey += $"({string.Join(",", parameters.Select(p => XmlDocParameterStr(api, p)))})"; } return(new ApiEntry(api, methodInfo, basis.AssemblyName, basis.NamespaceName, name, xmlDocKey, whitelist.IsWhitelisted(methodInfo))); }
public static async Task <ProgrammableBlockApi> LoadAsync(string whitelistCacheFileName) { var api = new ProgrammableBlockApi(); await Task.Run(() => { var members = new List <MemberInfo>(); var spaceEngineers = new SpaceEngineers(); var installPath = Path.Combine(spaceEngineers.GetInstallPath(), "bin64"); MDKUtilityFramework.Load(installPath); var dllFiles = Directory.EnumerateFiles(installPath, "*.dll", SearchOption.TopDirectoryOnly) .ToList(); foreach (var file in dllFiles) { LoadAssembly(file); } //var assemblies = dllFiles.Select(LoadAssembly).Where(a => a != null).ToList(); var assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); var whitelist = Whitelist.Load(whitelistCacheFileName); api._whitelist = whitelist; foreach (var assembly in assemblies) { Visit(whitelist, assembly, members); } // Hack. I'm getting duplicated entries and atm I cannot be bothered to do a proper check // for why... var visitedMembers = new HashSet <MemberInfo>(); foreach (var assemblyGroup in members.GroupBy(m => m.GetAssembly())) { foreach (var typeGroup in assemblyGroup.GroupBy(m => m.DeclaringType)) { if (typeGroup.Key == null) { foreach (var type in typeGroup) { var entry = api.GetEntry(type); if (!api._entries.Contains(entry)) { api._entries.Add(entry); } } continue; } var typeEntry = api.GetEntry(typeGroup.Key); if (typeEntry != null) { if (!visitedMembers.Add(typeEntry.Member)) { continue; } if (!api._entries.Contains(typeEntry)) { api._entries.Add(typeEntry); } foreach (var member in typeGroup) { var entry = api.GetEntry(member); if (entry != null) { if (!visitedMembers.Add(member)) { continue; } api._entries.Add(entry); } } } } } foreach (var entry in api.Entries) { entry.ResolveLinks(); } }); return(api); }