コード例 #1
0
        private static void AssertNoMethodsMatching(Func <MethodBase, MemberPolicy?, bool> matcher)
        {
            var policy  = new DefaultApiPolicyFactory().CreateSafeDefaultPolicy();
            var matched = new HashSet <string>();

            var filter = new ApiFilter(policy);

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in GetExportedTypesSafe(assembly))
                {
                    foreach (var method in type.GetMethods())
                    {
                        if (type.Namespace == null)
                        {
                            continue;
                        }

                        var result = filter.Filter(type.Namespace, type.Name, ApiFilterTypeKind.External, method.Name);
                        if (result.Kind != ApiFilterResultKind.Allowed)
                        {
                            continue;
                        }

                        if (matcher(method, result.MemberRule))
                        {
                            matched.Add(DescribeMethod(method));
                        }
                    }
                }
            }

            Assert.Empty(matched);
        }
コード例 #2
0
        private static IEnumerable <(MethodBase method, MemberPolicy?rule)> GetAllAllowedMethods()
        {
            var policy = new DefaultApiPolicyFactory().CreateSafeDefaultPolicy();

            var filter = new ApiFilter(policy);

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in GetExportedTypesSafe(assembly))
                {
                    foreach (var method in type.GetMethods())
                    {
                        if (type.Namespace == null)
                        {
                            continue;
                        }

                        var result = filter.Filter(type.Namespace, type.Name, ApiFilterTypeKind.External, method.Name);
                        if (result.Kind != ApiFilterResultKind.Allowed)
                        {
                            continue;
                        }

                        yield return(method, result.MemberRule);
                    }
                }
            }
        }