public ApiEntry GetEntry(MemberInfo memberInfo, bool includeBlacklisted = false)
        {
            if (memberInfo is Type type && type.IsGenericType)
            {
                memberInfo = type.GetGenericTypeDefinition();
            }

            if (_entryLookup.TryGetValue(memberInfo, out var entry))
            {
                if (entry != null || includeBlacklisted && _blacklistedEntryLookup.TryGetValue(memberInfo, out entry))
                {
                    return(entry);
                }
                return(null);
            }

            entry = CreateEntry(memberInfo);
            if (entry == null)
            {
                _entryLookup[memberInfo] = null;
                return(null);
            }

            if (_whitelist.IsWhitelisted(memberInfo))
            {
                _entryLookup[memberInfo] = entry;
                return(entry);
            }

            _blacklistedEntryLookup[memberInfo] = null;
            return(includeBlacklisted ? entry : null);
        }
Esempio n. 2
0
 void Visit(Whitelist whitelist, MemberInfo member)
 {
     if (!whitelist.IsWhitelisted(member))
     {
         return;
     }
     _members.Add(member);
 }
 static void Visit(Whitelist whitelist, MemberInfo member, List <MemberInfo> members)
 {
     if (member is Type type)
     {
         Visit(whitelist, type, members);
         return;
     }
     if (!member.IsPublic() || !whitelist.IsWhitelisted(member))
     {
         return;
     }
     members.Add(member);
 }
        static void Visit(Whitelist whitelist, Type type, List <MemberInfo> members)
        {
            if (!type.IsPublic() || !whitelist.IsWhitelisted(type))
            {
                return;
            }
            var typeMembers = type.GetMembers(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            foreach (var member in typeMembers)
            {
                Visit(whitelist, member, members);
            }
            //var nestedTypes = type.GetNestedTypes(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
            //foreach (var nestedType in nestedTypes)
            //    Visit(whitelist, nestedType, members);
        }
        static void Visit(Whitelist whitelist, Assembly assembly, List <MemberInfo> members)
        {
            if (!whitelist.IsWhitelisted(assembly))
            {
                return;
            }
            if (assembly.GetName().Name == "mscorlib")
            {
                return;
            }
            var companyAttribute = assembly.GetCustomAttribute <AssemblyCompanyAttribute>();

            if (companyAttribute?.Company == "Microsoft Corporation")
            {
                return;
            }
            var types = assembly.GetExportedTypes();

            foreach (var type in types)
            {
                Visit(whitelist, type, members);
            }
        }
Esempio n. 6
0
        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)));
        }
Esempio n. 7
0
        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)));
        }
Esempio n. 8
0
        static ApiEntry ForGenericType(ProgrammableBlockApi api, Whitelist whitelist, Type type)
        {
            var assemblyName   = type.Assembly.GetName().Name;
            var namespaceName  = type.IsGenericType ? type.GetGenericTypeDefinition().Namespace : type.Namespace;
            var name           = type.IsGenericType ? type.GetGenericTypeDefinition().Name : type.Name;
            var separatorIndex = name.IndexOf('`');

            if (separatorIndex >= 0)
            {
                name = name.Substring(0, separatorIndex);
            }
            var genericArguments = type.GetGenericArguments();
            var whitelistKey     = $"{namespaceName}.{name}";
            var xmlDocKey        = $"T:{whitelistKey}";

            xmlDocKey += "{" + string.Join(",", genericArguments.Select(arg => arg.IsGenericParameter ? arg.Name : arg.FullName)) + "}";
            return(new ApiEntry(api, type, assemblyName, namespaceName, name, xmlDocKey, whitelist.IsWhitelisted(type)));
        }
Esempio n. 9
0
        static ApiEntry ForType(ProgrammableBlockApi api, Whitelist whitelist, Type type)
        {
            if (!type.IsPublic && !type.IsNestedPublic && !type.IsNestedFamily && !type.IsNestedFamANDAssem && !type.IsNestedFamORAssem)
            {
                return(null);
            }
            if (type.IsGenericTypeDefinition || type.IsGenericType)
            {
                return(ForGenericType(api, whitelist, type));
            }

            var assemblyName  = type.Assembly.GetName().Name;
            var namespaceName = type.Namespace;
            var name          = type.Name;
            var xmlDocKey     = $"T:{namespaceName}.{name}";

            return(new ApiEntry(api, type, assemblyName, namespaceName, name, xmlDocKey, whitelist.IsWhitelisted(type)));
        }
Esempio n. 10
0
        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)));
        }
Esempio n. 11
0
        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)));
        }
Esempio n. 12
0
        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)));
        }
Esempio n. 13
0
        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)));
        }